2014-04-23 19 views
0

我有一個被調用的php腳本,它通過shell_exec()執行一個shell命令。這個shell命令需要不同階段的多個用戶輸入。我堅持要在每個輸入階段獲得交互性片段。執行從PHP到休息時間的用戶輸入

This is just an example of how I imagine it working... 
<?php 
$return = shell_exec('runcmd'); 

//Let runcmd run until first break 
echo $return; 
$userinput1 = 'foo'; 

//Let runcmd run until next break 
echo $return; 
$userinput2 = 'bar'; 

//Let runcmd run until nth break 
echo $return; 
$userinputNth = 'nth'; 
+0

最新大圖?我可以想象更好的選擇。 –

+0

我開放給替代品,主要問題是我沒有編寫shell腳本,但肯定需要通過網絡以某種方式與它交互。 – freeski

+0

ssh2_connect PHP擴展可能有效。 – KNaito

回答

0

要將輸入提供給shell命令,請使用popen

$handle = popen('runcmd', 'w'); 
fputs($handle, 'foo 
bar 
nth 
'); 
pclose($handle); 

由於沒有捕獲到輸出,所以我們不需要回顯它。

相關問題