PHP exec 使用参数启动 cmd 窗口

发布于 2024-12-05 13:03:44 字数 244 浏览 1 评论 0原文

我一直在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惯饮孤独 2024-12-12 13:03:44

确保批处理文件是可执行的,然后您可以简单地执行它:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文