views:

81

answers:

4

I am using open( my $command_out, "-|", $command_string ) to execute a command and process its output on the fly (not having to wait for the command to finish first, as in system()).

I noticed that when I call some R scripts this way, some of R messages are printed to the screen (e.g. Loading required package: ...). I guess this is because R sends this output to stderr (? although these are not really errors).

Is it possible to direct this output too to $command_out when open()-ing so the screen will remain clean?

+1  A: 

Maybe you could redirect STDERR to STDOUT for the whole program?

*STDERR = *STDOUT;
open( my $command.... );
cam
+2  A: 

An easy way is to append 2>&1 to $command_string, but whether or not this works will depend on your shell. (eg, the shell that interprets $command_string)

William Pursell
+3  A: 

Use IPC::Run to capture STDOUT and STDERR separately. The pump function gives you the output on the fly.

daxim
+1  A: 
Greg Bacon