我有bash和Perl腳本的集合bash腳本執行從PHP和瞬時輸出回到網頁
- 開發所需部署在Linux操作系統中
- (可選)出口代碼的目錄結構從SVN
- 從這個來源
構建一個軟件包這是從終端運作良好。現在我的客戶請求一個Web界面來處理這個過程。
例如,某些頁面上的「創建新包」按鈕將逐個調用上述步驟,並將輸出作爲腳本回顯返回給用戶,而不是在整個腳本執行時返回。
是否可以通過bash腳本將瞬時輸出發送到通過程序執行函數(system,exec,passthru ...或任何其他套件處理流程)調用它的網頁或php腳本?
什麼是優雅爲什麼要這樣做?
我在做這樣的事情時應該採取哪些安全防範措施(如果可能的話)?
編輯 一些搜索後,我已經找到了解決方案的一部分,但仍然沒有工作:
$cmd = 'cat ./password.txt|sudo -S ./setup.sh ';
$descriptorspec = 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", "w") // stderr is a pipe that the child will read from
);
flush();
$process = proc_open($cmd, $descriptorspec, $pipes, './', array());
echo "<pre>";
if (is_resource($process)) {
while ($s = fgets($pipes[1])) {
print "Message:".$s;
flush();
}
while ($s = fgets($pipes[2])) {
print "Error:".$s;
flush();
}
}
echo "</pre>";
輸出:(網頁),我現在有
Error:WARNING: Improper use of the sudo command could lead to data loss
Error:or the deletion of important system files. Please double-check your
Error:typing when using sudo. Type "man sudo" for more information.
Error:
Error:To proceed, enter your password, or type Ctrl-C to abort.
Error:
Error:Password:
Error:Sorry, try again.
Error:Password:
Error:Sorry, try again.
Error:Password:
Error:Sorry, try again.
Error:sudo: 3 incorrect password attempts**
首次發行是通過sudo passoword
請幫助!
相關:http://stackoverflow.com/questions/1281140/run-process-with-realtime-output-in-php http://stackoverflow.com/questions/133935/is-there-a-way- php-print-the-data-to-a-web-browser-in-time – jm666