From owner-freebsd-questions@FreeBSD.ORG Sun Apr 8 16:35:17 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2FC3916A402 for ; Sun, 8 Apr 2007 16:35:17 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout7.cac.washington.edu (mxout7.cac.washington.edu [140.142.32.178]) by mx1.freebsd.org (Postfix) with ESMTP id 0F4A213C468 for ; Sun, 8 Apr 2007 16:35:17 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.33.7] (may be forged)) by mxout7.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l38GZG3u015966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 8 Apr 2007 09:35:16 -0700 X-Auth-Received: from [192.168.10.45] (c-24-7-142-221.hsd1.ca.comcast.net [24.7.142.221]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l38GZGGQ012397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sun, 8 Apr 2007 09:35:16 -0700 Message-ID: <461919BE.7080903@u.washington.edu> Date: Sun, 08 Apr 2007 09:35:10 -0700 From: Garrett Cooper User-Agent: Thunderbird 1.5.0.10 (X11/20070325) MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: <46190C84.4080907@steelbox.org> In-Reply-To: <46190C84.4080907@steelbox.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-PMX-Version: 5.3.0.289146, Antispam-Engine: 2.5.0.283055, Antispam-Data: 2007.4.8.92333 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' Subject: Re: perl/script and retval X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Apr 2007 16:35:17 -0000 Olivier Regnier wrote: > Hello, > > I written a small script in sh : > # Downloading doc files > echo "===> Downloading doc files" > /usr/bin/csup $doc_supfile > RETVAL=$? > if [ $RETVAL != 0 ]; then > echo "abort" > exit 0 > fi > > I want to rewritte this code in perl script. > > my $retval=0; > my $doc_supfile="/etc/doc-supfile"; > > # Downloading doc files > print "===> Downloading doc files\n"; > system("/usr/bin/csup $doc_supfile > if (! $retval) { > print "abort"; > exit; > } > I don't know what happened with retval but that doesn't work correctly. > > Can you help me please ? > > Thank you :) Olivier, Why are you doing this all in perl? Doesn't Bourne shell suffice :)? Try: ==================================== #!/usr/local/bin/perl -w use strict; local $?=0; my $doc_supfile="/etc/doc-supfile"; print "===> Downloading doc files\n"; system "/usr/bin/csup $doc_supfile"; my $retval = $?; # make sure to grab exit val right after execution; # this can shoot you in the foot if you do it later on # down the line, and another command has been executed # behind the scenes.. Also read perldoc -f system for # more details on return codes because $retval doesn't # necessarily match the exit code that your shell may # see. unless($retval) { print "CVsup aborted\n"; exit $retval; } ==================================== See perldoc perlvar. Cheers, -Garrett