I’d like to execute a shell command and have the output in an array such that: (1) each line of the output is an element in the array (2) the lines are “tagged” as whether from stdout or stderr
Something like:
╔═════════╦══════════════════╗
║ Line No ║ Stdout or stderr ║
╠═════════╬══════════════════╣
║ Line1 ║ Stdout ║
╠═════════╬══════════════════╣
║ Line2 ║ Stdout ║
╠═════════╬══════════════════╣
║ Line3 ║ Stderr ║
╠═════════╬══════════════════╣
║ Line4 ║ Stdout ║
╚═════════╩══════════════════╝
This is a table, but what I really meant was a multi-dimensional array where $thisarray[0], $thisarray[1] are rows. I am assuming that the shell command executed will always generate a new line before it switches to either stderr or stdout.
This way, I'd be able to see which line belongs to which file descriptor, and be able to see it in context.
Is there any way to do this in PHP, with the shell exec commands or otherwise?
If this is not possible with PHP, I do not mind other technologies.