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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get exit status, STDOUT and STDERR of a command

Status
Not open for further replies.

topub

Programmer
Jun 6, 2006
42
US
Hi there,

searched faq's and google, but couldn't find a complete solution. so here I post my question.
any ideas are appreciated.

I need some way to run a OS command and get
1: exit status
2: STDOUT
3: STDERR
in three different variables.

I use open3 to run a command:
Code:
open3(gensym, \*CATCHOUT, ">&CATCHERR", $cmd);

I could get STDOUT And STDERR, but how to get exit status.
$?, didnt work.

any ideas.....
thanks,
_UB
 
I think system() returns the exit status...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
thanks Paul.
System does return exit status, but not the other two. I want 3 (STDOUT, STDERR, exit status) in three different variables.

thanks
 
You could write a little subroutine to execute the command. The subroutine could work by using system() to execute the command and redirect both outputs to temporary files, then read both files and return the standard output, error output, and exit code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top