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 intended 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 strictly forbidden.

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to