IPC::open3: What goes wrong?

B

bernd

Hello netties,

I try to run a simple UNIX-command using IPC::eek:pen and want to get the
command line's STDOUT, STDERR and the return code of the command using
the following:

cat script.pl
#!/usr/bin/perl
#
use IPC::Open3;
open3 (\*WRT, \*OUT, \*ERR, "ls -ly ; echo $?") or print "Could not
run unix-cmd\n";
@OUT = <OUT> ;
@ERR = <ERR>;
print "### OUT ###\n";
foreach ( @OUT ) { print "$_\n" } ;
print "### ERR ###\n" ;
foreach ( @ERR ) { print "$_\n" }

script.pl
### OUT ###
0

### ERR ###
ls: illegal option -- y

Usage: ls [-aAbcCdDfFgilLmnopqrRstux1] [file ... | directory ...]

On the command line "ls -ly" has the return code 2, run from within
perl I get 0.

What goes wrong?

Cheers


Bernd
 
B

Brian McCauley

open3 (\*WRT, \*OUT, \*ERR, "ls -ly ; echo $?")
On the command line "ls -ly" has the return code 2, run from within
perl I get 0.

What goes wrong?

You have the wrong type of quotes in Perl.

The Unix command you are actually executing is

ls -ly ; echo 0
 

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,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top