确保 proc_open 将使 PHP 中的命令行窗口保持活动状态
在 PHP 中,我使用 proc_open 在命令行运行命令。
它需要在新的 CMD 窗口中打开,因此我在命令的开头添加了“start”。
然而,它也需要保持打开状态才能显示结果,但实际上它会在之后自动关闭窗口。
我尝试添加“暂停”以及“保留”的 /k 选项。但两者都不起作用。窗户刚刚关上。
如何在使用 proc_open 时使窗口保持打开状态?
这是代码的一部分,$cmd 是前面填写的:
$descriptorspec = array(
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w'), // stderr
);
$process = proc_open($cmd, $descriptorspec, $pipes);
if (!is_resource($process))
{
throw new RuntimeException('Unable to execute the command.');
}
stream_set_blocking($pipes[1], false);
stream_set_blocking($pipes[2], false);
In PHP I am using proc_open to run a command at the command line.
It needs to open in a new CMD window, so I prepended 'start' to the beginning of the command.
However, it also needs to stay open to display the results, but actually it closes the window automatically afterwards.
I have tried adding 'pause' and also the /k option to 'remain'. But neither work. The window just shuts.
How can I make the window stay open when using proc_open?
This is part of the code, $cmd is filled earlier:
$descriptorspec = array(
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w'), // stderr
);
$process = proc_open($cmd, $descriptorspec, $pipes);
if (!is_resource($process))
{
throw new RuntimeException('Unable to execute the command.');
}
stream_set_blocking($pipes[1], false);
stream_set_blocking($pipes[2], false);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“start”将启动指定的命令,然后退出。它基本上是异步的。您可能会更幸运,让您的 proc_open 启动一个运行批处理文件的 cmd shell,并从 .bat 内部运行您的命令,之后您可以执行“暂停”
"start" will fire up the specified command and then exit. It's basically asynchronous. You might have better luck having your proc_open start a cmd shell which runs a batch file, and run your command from inside the .bat, after which you can do a 'pause'