仕事のようですproc_open
ね!
実行するコマンドを渡し、次に、プロセスのstdin、stdout、およびstderrを表すために開くストリームの説明を含む配列を渡します。
ストリームは事実上ファイルハンドルであるため、ファイルに書き込んでいるかのように簡単に書き込むことができます。
たとえば、私自身のコードベースの印刷ビットから:
// In this case, $data is a PDF document that we'll feed to
// the stdin of /usr/bin/lp
$data = '';
$handles = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "a") // stderr is a file to write to
);
// Setting of $server, $printer_name, $options_flag omitted...
$process_name = 'LC_ALL=en_US.UTF-8 /usr/bin/lp -h %s -d %s %s';
$command = sprintf($process_name, $server, $printer_name, (string)$options_flag);
$pipes = array();
$process = proc_open($command, $handles, $pipes);
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// As we've been given data to write directly, let's kinda like do that.
fwrite($pipes[0], $data);
fclose($pipes[0]);
// 1 => readable handle connected to child stdout
$stdout = fgets($pipes[1]);
fclose($pipes[1]);
// 2 => readable handle connected to child stderr
$stderr = fgets($pipes[2]);
fclose($pipes[2]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);