问题描述
可能的重复:
php 我该怎么做启动一个外部程序运行 - 系统和执行有问题
如何用php打开exe?
我有这个想法并努力成功了好几年,但最终失败了.有人告诉我完成这项工作的成功方法吗?
how to open exe with php?
I had this idea and make hard to success it for several years,but failed at last. any one tell me a success method to do the job ?
<?php
if(isset($_POST['file_path'])){
/* -------
using "notepad++.exe" to open "test.php" file.
or run a bat file which calling "notepad++.exe" to open "test.php" file.
how to seting php.ini or firefox or any setting to do this job.
it is only for conveniently developing web page in my PC ,not for web servers
------- */
}
?>
<form action="test.php" method="post">
<input type="text" name="file_path" value="test.php"/>
<button type="submit">open with notepad++</button>
</form>
这将创建类似:
推荐答案
在运行网络服务器的计算机上启动一个程序:
To launch a program on the computer which runs the webserver:
<?php
exec('"C:Program Files (x86)Notepad++
otepad++.exe" "C:foo.php"');
如果网络服务器不作为 Windows 服务运行,上述内容将适用于 vista/win7.例如,如果您运行 apache 并且它会在您的计算机启动时自动启动,那么您可能将它安装为一项服务.您可以检查 apache 是否出现在 windows 服务选项卡/thingy 中.
The above will work on vista/win7 IF the webserver does not run as a windows service. For example, if you run apache and it automatically starts when your computer boots, you probably installed it as a service. You can check to see if apache shows up in the windows services tab/thingy.
如果网络服务器作为服务运行,您需要考虑为该服务启用允许桌面交互"选项.但除此之外:
If the webserver runs as a service, you'll need to look into enabling the "allow desktop interaction" option for the service. But otherwise:
使用 php 的新内置网络服务器(php 5.4+)的简单测试.这里的关键是您从 shell 手动启动服务器,因此它作为您的用户而不是作为服务运行.
An easy test using php's new built in webserver(php 5.4+). The key thing here is you manually start the server from a shell, so it runs as your user instead of as a service.
<?php
// C:myhtdocsscript.php
exec('"C:Program Files (x86)Notepad++
otepad++.exe" "C:foo.php"');
通过命令窗口启动网络服务器
start a webserver via a command window
C:path ophp.exe -S localhost:8000 -t C:myhtdocs
然后在您的浏览器中http://localhost:8000/script.php
这篇关于如何使用 PHP 启动 Windows GUI 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!