PHP显示CMD命令提示符窗口(Windows) [英] PHP Show CMD Command Prompt Window (Windows)
问题描述
通常,您想要隐藏CMD窗口。
在我的例子中,我将使用PHP + CLI进行一些测试。
如果PHP可以启动CLI弹出窗口,这将是非常有用的。
但是唉,我找不到一个办法让它。
Usually, you would want to hide the CMD window. In my case, I'll be doing some tests with PHP+CLI. It will be mighty useful if PHP could be made to launch a CLI popup. But alas, I can't find a way to make it to.
以下命令应该使它工作,但它不: / p>
The following command should have made it work, but it doesn't:
START "PHP AE2" CMD /K DIR
有问题的PHP代码基于 proc_open()
:
The PHP code in question is based on proc_open()
:
$proc=proc_open($cmd,array(
0=>array('pipe','r'), // STDIN
1=>array('pipe','w'), // STDOUT
2=>array('pipe','w') // STDERR
),$pipes);
// ....some stream stuff....
$return=proc_close($proc);
虽然命令运行正常,弹出窗口不会显示。我怀疑这是Apache的一个特性。有没有办法将CMD从其父级完全分离?
Although the command runs fine, the popup doesn't show up. I suspect this is a feature of Apache. Is there a way to completely detach the CMD from its parent?
此外,我将用 DIR
一个用于初始化环境的小脚本/批处理/程序,所以重要的是我可以在弹出窗口后执行一个程序。
Also, I'll be substituting DIR
with a small script/batch/program that initializes the environment, so it is important that I can execute a program after the popup shows up.
(这主要是为了教育目的)
(This is mostly for educational purposes and won't follow into production.)
推荐答案
我有点晚了回答这个问题,但是为了帮助关闭这个问题是我的回答。
I am bit late to answering this question, but to help close this question here is my answer.
命令是正确的,但您需要让Apache与桌面交互。如果你在Windows机器上,只需去服务,找到Apache,并确保勾选允许服务与桌面交互复选框。
The command is correct but you need to get Apache to interact with the desktop. If you are on a windows machine, just go to services, find Apache and make sure you tick the "Allow Service to Interact with desktop" checkbox.
这篇关于PHP显示CMD命令提示符窗口(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!