2013-07-17 40 views
0

我用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。

+0

挑剔:有沒有這樣的事,作爲一個「C腳本」。你的第二個proc_open調用中還有一個輸入錯誤,在第一個參數後面。 –

+0

我的意思是C代碼,簡單的C程序。至於','和';'在行結束時,複製過程中可能是一個錯誤。 – georgia

回答

0

如果過程可以單獨運行一個又一個

你可以試試把「在步驟」,

/** step 1*/ 
$process1 = proc_open($command_exe1, $descriptorspec1, $pipes1, $cwd) 
... 
while(!feof($pipes1[1])) { 
       $StdOut1 = stream_get_contents($pipes1[1]); 
       } 
     echo $StdOut1; 


/** step 2*/ 

$process2 = proc_open($command_exe2 $descriptorspec2, $pipes2, $cwd) 
while(!feof($pipes2[1])) { 

...

+0

問題是如果我想在每個程序中有2個輸入和輸出不起作用。我的意思是每個代碼可以得到2個數字並打印他們的double/duadruple。 – georgia