PHP exec启动一个带参数的cmd窗口 [英] PHP exec to launch a cmd window with parameters

查看:237
本文介绍了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.

提前感谢

推荐答案

确保批处理文件是可执行文件,然后可以直接执行:

Make sure the batch file is executable, then you can simply exec it:

exec('myscript.bat'); code>

exec('myscript.bat');

您不应该通过cmd执行。如果你由于某种原因,你将不得不像在命令行中一样提供额外的参数:

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

将向您展示如何为cmd提供其他选项

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.

这篇关于PHP exec启动一个带参数的cmd窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆