System calls question

T

tweetiebirds

When calling system I would like the standard output to be printed to
standard out.

This is not happening - how do I make it happen:


system ("cp a b");


T
 
D

Damian James

When calling system I would like the standard output to be printed to
standard out.
This is not happening - how do I make it happen:
system ("cp a b");

print `cp a b`;

perldoc -q "Why can't I get the output of a command with system()?"
perldoc -f system

and see the section on qx// in perldoc perlop

Or if you need to take more control over the other process, see
the pipe version of open (ie, where MODE is '-|')

perldoc -f open


Cheers,
Damian
 
J

jesper

When calling system I would like the standard output to be printed to
standard out.

This is not happening - how do I make it happen:


system ("cp a b");


T
Well try

$result = `cp a b`;
printf $result;

does only print after execution though.
 
M

Mark Clements

Damian said:
print `cp a b`;

perldoc -q "Why can't I get the output of a command with system()?"
perldoc -f system

and see the section on qx// in perldoc perlop

Or if you need to take more control over the other process, see
the pipe version of open (ie, where MODE is '-|')

perldoc -f open

That being said, you won't get any output on stdout with the above
command, though you may get some on stderr.

Mark
 
D

Damian James

That being said, you won't get any output on stdout with the above
command, though you may get some on stderr.

Indeed. And system() does indeed send the other program's STDOUT to STDOUT,
so my suggestion above was pointless. Two things I just didn't spot, not
really my day ;)

--damian
 
J

Joe Smith

When calling system I would like the standard output to be printed to
standard out.

system ("cp a b");

Change that to either
system("cp -v a b");
or
system("cat a b");
depending on what you're really trying to accomplish.
-Joe
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top