ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
RE: system/backticks output not as expected
by Brian Raven other posts by this author
Oct 30 2009 6:57AM messages near this date
system/backticks output not as expected | Re: system/backticks output not as expected
Oeschey, Lars (I/ET-83, extern) <>  wrote:
>  Hi,
>  
>  I have a problem getting the output of a system call. It's a simple
>  code:
>  
>  my $return=`$command`;
>  print "$?\n";
>  print "result:$return\n";
>  
>  (I am calling a command which actually doesn't exist, to check error
>  handling)
>  
>  as result on the console I have:
>  
>  Das System kann das angegebene Laufwerk nicht finden.
>  256
>  result:
>  
>  The first error says it can't find the program. Actually I expected
>  this in $return. 
>  
>  compared to system():
>  
>  my $return=system("$command");
>  print "$?\n";
>  print "result:$return\n";
>  
>  Das System kann das angegebene Laufwerk nicht finden.
>  256
>  result:256
>  
>  So obviously system() returns the error code. But why don't the
>  backticks return anything at all? Ideally I'd want all the output
>  catched to log, but still be able to react on errors...  

Backticks only capture output from stdout, while error messages are
generally output on stderr. In unix-like shells it usual to redirect
stderr to stdout by adding 2> &1 to the command line. I don't know if it
works the same on win32, but it might be worth a try, if that is your
platform.

Also, you could always try verifying that the command exists before
trying to run it.

HTH

-- 
Brian Raven 
This e-mail may contain confidential and/or privileged information. If you are not the inten
ded recipient or have received this e-mail in error, please advise the sender immediately by
 reply e-mail and delete this message and any attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this e-mail is stric
tly forbidden.

_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Lars Oeschey
Brian Raven
Serguei Trouchelle
Conor Lillis

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved