catch error code from system()

J

justme

hi

i wrote a perl script that is supposed to run a java program.

my $cmd ="/usr/bin/java javaprog";
system($cmd);

the java prog returns an error code if there is an error when the java prog runs
how can i catch the return code of the java prog reliably ?
thanks
 
S

Sam Holden

hi

i wrote a perl script that is supposed to run a java program.

my $cmd ="/usr/bin/java javaprog";
system($cmd);

the java prog returns an error code if there is an error when the java prog runs
how can i catch the return code of the java prog reliably ?
thanks

What does the documentation for the perl system function say?
 
P

Paul Lalli

hi

i wrote a perl script that is supposed to run a java program.

my $cmd ="/usr/bin/java javaprog";
system($cmd);

the java prog returns an error code if there is an error when the java prog runs
how can i catch the return code of the java prog reliably ?
thanks

Uhm, by not throwing away the return value from system?

my $retval = system($cmd);

(note that one more step is actually needed. Read
perldoc -f system
for more info)

Paul Lalli
 
J

Jürgen Exner

justme said:
i wrote a perl script that is supposed to run a java program.

my $cmd ="/usr/bin/java javaprog";
system($cmd);

the java prog returns an error code if there is an error when the
java prog runs how can i catch the return code of the java prog
reliably ? thanks

Please provide a complete but minimal program that demonstrates that the
method described in the documentation for system() doesn't work.
Then people will sure be happy to investigate.

jue
 
T

Tad McClellan

justme said:
how can i catch the return code of the java prog reliably ?


Please do not ask thousands of people to read the docs to you.


perldoc -f system
 
J

J. Romano

i wrote a perl script that is supposed to run a java program.

my $cmd ="/usr/bin/java javaprog";
system($cmd);

the java prog returns an error code if there is an error when the java prog runs
how can i catch the return code of the java prog reliably ?

There are several ways (read "perldoc -f system" to find out what
some of them are). One of the simplest ways is to check the $?
variable, like this:

my $cmd ="/usr/bin/java javaprog";
system($cmd);
my $errorCode = $? >> 8; # don't forget the ">> 8" part!
print "The error-code from the command was $errorCode.\n";

Hope this helps. You might also want to read the "perldoc perlvar"
documentation and search for the "$?" variable for more advice.

-- J.
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top