php - 在从 PHP 到 Shell 的中断处执行用户输入

标签 php linux shell

我有一个被调用的 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/

相关文章:

php - 如何将缩略图存储到数据库中?

php - 使用数组仅将选定的值传递给函数

php - 保存结帐自定义字段,将值合并到 WooCommerce 中的现有字段

javascript - 使用 javascript 将 .php 加载到 div 中

linux - 在 ubuntu 32 位上构建 trilinos 时出现内部 cmake 错误

linux - 在这种情况下,Crystal Reports 是可行的选择吗?

linux - 无法为 Ubuntu 安装 LightTable

bash - 如何在heroku procfile中编写多行命令

c++ - system() 在作为 CGI 调用时总是返回非零值

c - 如果我无权访问文件,如何在 shell 中打开该文件?