我有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