从PHP运行shell脚本并查看完整的进度?

从PHP运行shell脚本并查看完整的进度?,第1张

概述从PHP运行shell脚本并查看完整的进度

有没有办法从PHP运行一个shell脚本,并在进度完成后回显结果?

这是我的shell脚本:

(它的多行 – 一些命令必须依次运行。)

cd cd /var/www/HTML/ npm uninstall gulp --save npm install gulp --save npm start

这是我目前正在运行的PHP脚本。 它只输出一些进度,只在完成时输出。 我需要现场预览进度。

如何使用gulp-rsync和cygwin使用ssh密钥

量angular器Js运行到linux机器

gulp.watch()没有运行相关的任务

在windows上使用Node.Js作为本地用户

如何使用gulp-open启动Microsoft Edge浏览器?

<?PHP echo "loaded<br><br>"; // echo shell_exec("cd /var/www/HTML/.."); // rin the shell scrip from header_register_callback echo '<pre>'; // Outputs all the result of shellcommand "ls",and returns // the last output line into $last_line. Stores the return value // of the shell command in $retval. $last_line = system('cd /var/www/HTML/; npm start',$retval); // Printing additional info echo ' </pre> <hr />Last line of the output: ' . $last_line . ' <hr />Return value: ' . $retval; ?>

这是另一种方法。 它使用重定向来输出结果,然后使用file_get_contents()来读取输出。

<?PHP echo "loaded<br><br>"; $cmd = 'npm start'; $run = $cmd . ' > result.txt 2> errors.txt'; $output = shell_exec($run); $results = file_get_contents('result.txt'); if (strlen(file_get_contents('errors.txt')) != 0) { $results .= file_get_contents('errors.txt'); } echo "<pre>$results</pre>"; ?>

我想,ob_flush()将工作:

<?PHP echo "loaded<br><br>"; ob_flush(); // echo shell_exec("cd /var/www/HTML/.."); // rin the shell scrip from header_register_callback echo '<pre>'; ob_flush(); // Outputs all the result of shellcommand "ls",$retval); // Printing additional info echo ' </pre> <hr />Last line of the output: ' . $last_line . ' <hr />Return value: ' . $retval; ?>

但是我不明白为什么当你在控制台上运行这个脚本时,你会回显HTML-Tags …希望我能理解你

总结

以上是内存溢出为你收集整理的从PHP运行shell脚本并查看完整的进度?全部内容,希望文章能够帮你解决从PHP运行shell脚本并查看完整的进度?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1157958.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-01
下一篇2022-06-01

发表评论

登录后才能评论

评论列表(0条)

    保存