Thanks for your response, Roldano. I decided to follow your suggestion with
Perl to remove the possibility of my misunderstanding Ruby syntax. I tried
the following Perl script

#!/usr/bin/perl
$var = system("hadoop dfs -test <param>");
print "\"$var\"";

Here are my results for the given value of <param>:

*Test           Value of <param>                                 Result*
1                -d <name of existing directory>                    0
2                -d <name of existing file>                           256
3                -d <name non-existing directory>               65280
4                -e <name of existing directory>                    0
5                -e <name of existing file>                             0
6                -e <name of non-existing file>                     256

In the above, "non-existing" means I used a file/directory name that was not
equivalent to any of the files/directories in the file system. The results
for tests 4 and 5 are what I would expect. The result for test 6 is a bit
unsatisfying but I guess it doesn't violate the contract. My concern is with
the result for tests 1-3. The result for test 1 should be "1" and the result
for tests 2 and 3 should both be "0". I'm basing this on

http://hadoop.apache.org/core/docs/current/hdfs_shell.html

Has anyone else used the Hadoop FS shell and got these results or are you
having better luck? Am I missing something here?

Note that I tried this with Hadoop 0.19.0 with both S3 Native and HDFS.

Thanks,
John



On Mon, Feb 23, 2009 at 11:43 AM, Roldano Cattoni <[email protected]> wrote:

> 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
>

Reply via email to