Return-Path: Delivered-To: apmail-hadoop-core-user-archive@www.apache.org Received: (qmail 80102 invoked from network); 23 Feb 2009 16:44:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Feb 2009 16:44:29 -0000 Received: (qmail 47347 invoked by uid 500); 23 Feb 2009 16:44:22 -0000 Delivered-To: apmail-hadoop-core-user-archive@hadoop.apache.org Received: (qmail 47293 invoked by uid 500); 23 Feb 2009 16:44:22 -0000 Mailing-List: contact core-user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: core-user@hadoop.apache.org Delivered-To: mailing list core-user@hadoop.apache.org Received: (qmail 47282 invoked by uid 99); 23 Feb 2009 16:44:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Feb 2009 08:44:22 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [217.77.80.3] (HELO lancelot.fbk.eu) (217.77.80.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Feb 2009 16:44:14 +0000 X-AuditID: d94d5003-ab2c9bb00000303b-08-49a2d24413ff Date: Mon, 23 Feb 2009 17:43:48 +0100 From: Roldano Cattoni To: "core-user@hadoop.apache.org" Subject: Re: Can anyone verify Hadoop FS shell command return codes? Message-ID: <20090223164348.GA15509@fbk.eu> References: <4f10e2890902230502xafa5a41g9b706df3b17ad359@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <4f10e2890902230502xafa5a41g9b706df3b17ad359@mail.gmail.com> User-Agent: Mutt/1.5.14 (2007-02-12) X-Brightmail-Tracker: AAAAAA== X-Virus-Checked: Checked by ClamAV on apache.org 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