On Mon, Feb 23, 2009 at 4:02 PM, S D wrote: > I'm attempting to use Hadoop FS shell (http://hadoop > .apache.org/core/docs/current/hdfs_shell.html) within a ruby script. My > challenge is that I'm unable to get the function return value of the > commands I'm invoking. As an example, I try to run get as follows > > hadoop fs -get /user/hadoop/testFile.txt . > > From the command line this generally works but I need to be able to verify > that it is working during execution in my ruby script. The command should > return 0 on success and -1 on error. Based on > > http://pasadenarb.com/2007/03/ruby-shell-commands.html > > I am using backticks to make the hadoop call and get the return value. Here > is a dialogue within irb (Ruby's interactive shell) in which the command was > not successful: > > irb(main):001:0> `hadoop dfs -get testFile.txt .` > get: null > => "" > > and a dialogue within irb in which the command was successful > > irb(main):010:0> `hadoop dfs -get testFile.txt .` > => "" > > In both cases, neither a 0 nor a 1 appeared as a return value; indeed > nothing was returned. Can anyone who is using the FS command shell return > values within any scripting language (Ruby, PHP, Perl, ...) please confirm > that it is working as expected or send an example snippet?
You seem to confuse captured output of stdout and exit status. Try analyzing $?.exitstatus in Ruby: irb(main):001:0> `true` => "" irb(main):002:0> $?.exitstatus => 0 irb(main):003:0> `false` => "" irb(main):004:0> $?.exitstatus => 1 -- WBR, Mikhail Yakshin
