hadoop-common-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roldano Cattoni <catt...@fbk.eu>
Subject Re: Can anyone verify Hadoop FS shell command return codes?
Date Mon, 23 Feb 2009 16:43:48 GMT
You should distinguish between the output of a command and the return value
of the command: usually they are captured in different ways by the
interpreters (scripting languages or shells).

For example:

1) in perl the return value is captured by using the system function:
   $rv = system("cmd");
so the $rv variable contains the value returned by cmd. 
Instead, with backticks you get the output of cmd:
   $out = `cmd`;

2) in shells (sh/bash/tcsh) the return value is stored in the variable $?
(dollar char followed by question-mark char).
Instead, the output is again obtained with backticks.

I don't know the way in which irb captures the return value: for analogy I
would say that backticks are used for capturing the output even in irb.

Best

  Roldano



On Mon, Feb 23, 2009 at 02:02:22PM +0100, 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?
> 
> Thanks,
> John

Mime
View raw message