我有一个被调用的 php 脚本,它通过 shell_exec() 执行 shell 命令。此 shell 命令需要在不同阶段进行多个用户输入。我一直致力于让交互部分在每个输入阶段正常工作。
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';
最佳答案
要将输入提供给 shell 命令,请使用 popen
.
$handle = popen('runcmd', 'w');
fputs($handle, 'foo
bar
nth
');
pclose($handle);
由于未捕获输出,因此我们不需要回显它。
关于php - 在从 PHP 到 Shell 的中断处执行用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23233702/