gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:00:20 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com