How to get an exit code from a 'shell' command ?

N

Nanard

Hi,

I know how to get the the exit code of my command when I do a :
system("myCommand p1 p2")

I don't know when I run my command using :
my @list_stdout = `myCommand p1 p2`;
How to get the exit code of my command ?

If I run :
my $pid = open ( PIPE , "| myCommand p1 p2");
print PIPE "ls";
print PIPE "exit";
close PIPE;
How to know the exit code of myCommand ?

Thanks for the answers.
 
S

Sherm Pendley

Nanard said:
I don't know when I run my command using :
my @list_stdout = `myCommand p1 p2`;
How to get the exit code of my command ?

If I run :
my $pid = open ( PIPE , "| myCommand p1 p2");
print PIPE "ls";
print PIPE "exit";
close PIPE;
How to know the exit code of myCommand ?

It's in the $? variable. For a full description, see "perldoc perlvar".

sherm--
 
N

Nanard

Yes :
my $ret = `echo $?`;

give me the exit code of my command.

Unfortunately, for the 'ftp' command, I always has a 0 return value !
 
J

Jürgen Exner

Nanard wrote:
[Adding back snipped context]
Sherm said:
It's in the $? variable. For a full description, see "perldoc
perlvar".
[End of added context]
Yes :
my $ret = `echo $?`;
????

give me the exit code of my command.

Well kind a sort of. Why are you shelling out an external program just to
echo the value of a variable? That doesn't make much sense unless your goal
is to burn some CPU and HD cycles.
Why not a simple
print $?;
Unfortunately, for the 'ftp' command, I always has a 0 return value !

Well, you got an error on line 42.
Hint: if you don't show us a minimal script that demonstrates the problem
then we have pretty much no way to analyse issue.

jue
 
T

Tintin

Nanard said:
Yes :
my $ret = `echo $?`;

give me the exit code of my command.

Unfortunately, for the 'ftp' command, I always has a 0 return value !

Then use Net::FTP and get full control over exit statuses.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top