簡體   English   中英

如何在 php 中使用 exec 顯示 bash 腳本命令執行的指示?

[英]How to show indication for bash script commands execution using exec in php?

我有一個 bash 腳本文件"myApp.sh" ,其中包含許多命令(用於循環、構建數據庫、將數據導入數據庫、調用其他 bash 腳本文件)。 命令很復雜。

我正在使用exce方法從 PHP 頁面調用此"myApp.sh"

$contents = file_get_contents('../myApp.sh');
$output = null;
$return_var = null;
$contents = escapeshellarg($contents);
exec("/usr/local/bin/bash -c $contents 2>&1", $output, $return_var);
  echo "<hr>";
  print_r($output);
echo "<hr>";

現在,我想為用戶顯示加載或百分比進度條,因為這些命令有時需要超過 15 分鍾才能完成。

我怎樣才能為用戶顯示一些進度條? 或者在運行時同時顯示每個命令的 output?

注意: proc_open不適用於我的腳本,它在面對 for 循環或調用另一個腳本文件時停止。 因此,唯一適用於我的腳本的 function 是exec

我過去寫過這樣的腳本,usint tput 實用程序。

https://github.com/realSpok/progressbar

您可以這樣使用它:

progress $k $total

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM