我用C創建了兩個程序。第一個獲取一個數字並打印它的double值,第二個打印四個數字。
我想通過PHP執行它們 。我已經使用proc_open完成了它,並且如果我每次只執行一個程序,它就可以正常工作。
我必須給第一個程序編號 ,並將其輸出作爲輸入傳遞給第二個程序。雖然我使用兩個proc_open來創建兩個進程,但整個事情都不起作用。 我想要做的是這樣的:PHP用proc_open執行兩個C程序
$process1 = proc_open($command_exe1, $descriptorspec1, $pipes1, $cwd);
$process2 = proc_open($command_exe2, $descriptorspec2, $pipes2, $cwd);
fwrite($pipes1[0], $posted);
fwrite($pipes2[0], $pipes1[1]);
fclose($pipes1[0]);
fclose($pipes2[0]);
while(!feof($pipes1[1])) {
$StdOut1 = stream_get_contents($pipes1[1]);
}
echo $StdOut1;
while(!feof($pipes2[1])) {
$StdOut2 = stream_get_contents($pipes2[1]);
}
echo $StdOut2;
fclose($pipes1[1]);
fclose($pipes2[1]);
proc_close($process1);
proc_close($process2);
我知道這是做這件事的錯誤的方式,但我想不出別的所以...任何幫助將受到歡迎。 注意:我正在使用Windows。
挑剔:有沒有這樣的事,作爲一個「C腳本」。你的第二個proc_open調用中還有一個輸入錯誤,在第一個參數後面。 –
我的意思是C代碼,簡單的C程序。至於','和';'在行結束時,複製過程中可能是一個錯誤。 – georgia