开发者

Ensuring proc_open will keep the command line window alive in PHP

开发者 https://www.devze.com 2023-01-14 05:01 出处:网络
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.

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);


"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'

0

精彩评论

暂无评论...
验证码 换一张
取 消