Skip to content
Advertisement

php run command line and pipe std err to variable

I am trying to figure out how to run a command line program within php and output both stout and stderr to a variable. All the examples either output the command line directly to the screen, or only output stdout for example

JavaScript

will output the following directly to the screen and not store anything in $data

JavaScript

And the following will store the output in $data

JavaScript

because it is going to std out since there is no error. So the question is how can I route the std error to a variable as well when running command line programs from php?

This question does not answer my question because I am trying to do the exact OPPOSITE. I am trying to get it to a variable. PHP – How to get Shell errors echoed out to screen

Thank you

Advertisement

Answer

ok I was able to find a solution. You need to set up a native process to configure the pipes.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement