How can I capture STDERR and get an exit code?

J

Jake Cahoon

I need to run a system command, find out if it failed and put its
output in a log file. The way I am trying to do it right now is to
get the exit code from the command with system() but then I don't know
how to capture its output. The backticks are the opposite problem. I
can capture the command's output but I don't know what its exit code
is. It just seems like an ugly solution to me to have to pattern
match the command's output just to see if the command executed
successfully.

Anyone have some tips?

Thanks,

J Cahoon
 
P

Paul Lalli

I need to run a system command, find out if it failed and put its
output in a log file. The way I am trying to do it right now is to
get the exit code from the command with system() but then I don't know
how to capture its output. The backticks are the opposite problem. I
can capture the command's output but I don't know what its exit code
is. It just seems like an ugly solution to me to have to pattern
match the command's output just to see if the command executed
successfully.

Anyone have some tips?

Read perldoc perlvar. Look for the section on the $? variable. Read it
thoroughly. It might not be *quite* what you expect.

Paul Lalli
 
P

Paul Lalli

Read perldoc perlvar. Look for the section on the $? variable. Read it
thoroughly. It might not be *quite* what you expect.

Paul Lalli

Re-reading your post, you might be better off or at least aided by reading
the FAQ on this topic:

perldoc -q STDERR
"How can I capture STDERR from an external command?"


Paul Lalli
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top