PHP exec 使用参数启动 cmd 窗口
我一直在尝试使用 php exec 方法启动 cmd 窗口。这个想法是启动 cmd 并让它开始运行文件。我的第一个问题是,当用户更改信息(例如用户信息或他们想要启动的工具)时,能够在 PC 上重写 bat 文件。现在这不再是问题了。我能够使用 php popen 函数来通过它。从我所做的所有阅读中,我能够确定可以使用一个附加命令来启动 cmd,告诉它启动批处理文件。我只需要一个很好的例子,这样我就可以理解它。如果有人可以提供帮助,我将非常感激。
提前致谢
I have been trying to launch a cmd window using the php exec method. The idea is to launch cmd and get it to start running a file. My first problem was being able to rewrite the bat file on the PC when user changes the information such as their user information or what tools they would like to launch. Now that is no longer a problem. I was able to use php popen function to get passed that. From all the reading I have done I was able to determine that it is possible to launch cmd with an additional command telling it to launch the batch file. I just need a good example so I can wrap my head around it. If anybody can help I would really appreciate it.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保批处理文件是可执行的,然后您可以简单地执行它:
exec('myscript.bat');
您不需要通过 cmd 来执行此操作。如果您出于某种原因想要这样做,则必须提供额外的参数,就像在命令行上一样:
exec('cmd /C myscript.bat');
http://ss64.com/nt/cmd.html
将向您展示如何向 cmd 提供其他选项(并解释其中一个多于)。
玩得开心,如果遇到任何问题请告诉我。
Make sure the batch file is executable, then you can simply exec it:
exec('myscript.bat');
You shouldn't need to do it via cmd. If you want to for some reason, you will have to provide extra parameters just as you would on the command line:
exec('cmd /C myscript.bat');
http://ss64.com/nt/cmd.html
will show you how to provide other options to cmd (and explain the one above).
Have fun, let me know if you get any problems.