Search code examples
rperlpipeexecution

Direct STDERR when opening pipe in perl


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?


Solution

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