Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get an answer from a `command` .

Status
Not open for further replies.

shlomyb

Programmer
Nov 14, 2006
32
IL
I use `a.pl` command inside my script.
I want to get the answer from `a.pl` (success/fail).
1.can I use ?

`a.pl`;
$answer=$?;

2.I try it and when a.pl returns 1 $answer was 256 ?!
Can someone explain it to me ?
 
If you execute a command in backticks or qx{}, perl returns the resulting STDOUT as a list, e.g.
Code:
my @files = qx{ls -al};
If you invoke a command using the system call, you get the return code, not the output.

Does this help at all?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
$files=qx{ls -al}; should also work, the array is a nice feature though

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top