I am looking for something in php that would given output (raw) of a system command in a variable along with the return code.
execdoes this, but the output is in array and hence the data returned is not proper(as\ncomes in new index).systemoutputs the data in the output stream and not in a variable.shell_execdoes not give the return value but gives raw data.
Sounds like you’re looking for output buffering:
This should preserve all white-space characters at the end of each output line (
execas you wrote destroys these, soimplodewould not be an option).Alternatively, you can open a process and aquire the pipes (standard output, STDOUT) and read the output out of these. But it’s more complicated (but gives you more options). See
proc_open.