This is a little tricky so bear with me:
- I have a PHP script
a.phpthat is launched from the command line and data is provided to it viaSTDIN - I have another PHP script
b.php - I want to have
a.phplaunchb.phpand capture its output. - Also,
a.phphas to forward theSTDINtob.php
Is there an easy way to do this?
For just capturing the stdout of another program (php or not), you can use backticks:
http://php.net/manual/en/language.operators.execution.php.
For example:
To capture stdin, do this:
Finally, to pipe the contents of a string to an external program, use proc_open, as suggested by jeremy’s answer.
Specifically, here’s what your a.php should contain: