运行php exec()来运行可执行文件会使浏览器无限期地加载

时间:2016-04-04 13:43:18

标签: php amazon-web-services

我正在尝试使用PHP的exec()函数在我的AWS Windows Server 2012实例上运行exe文件来执行命令。但它使我的浏览器无限期地显示加载。当我在服务器上执行命令时,命令运行完美。 我跑的时候

echo exec('whoami');

返回帐户用户名。所以一些命令正在通过php工作。但是当我运行我的可执行文件时:

echo exec('myfile.exe');

它使浏览器继续显示加载。 (我已将我的exe路径添加到环境变量中,以便我可以从命令提示符直接访问我的exe)

感谢任何帮助。 感谢

1 个答案:

答案 0 :(得分:0)

我想在这里做的是,通过浏览器在我的服务器上打开一个exe文件。 我设法使用我在答案中找到的以下PHP代码来完成它:

shell_exec('SCHTASKS /F /Create /TN _notepad /TR "notepad.exe" /SC DAILY /RU INTERACTIVE');
shell_exec('SCHTASKS /RUN /TN "_notepad"');
shell_exec('SCHTASKS /DELETE /TN "_notepad" /F');

这将在您的服务器上打开记事本。您可以使用notepad.exe替换exe文件的路径 这适用于Windows 8.1,Windows 10和Windows 2012 Server

您还可以尝试以下步骤启用Apache服务来运行桌面应用程序:

Start->Run, type "services.msc" to bring up Services control (other ways to get there, this is easiest IMO)
Locate your Apache service (mine was called "wampapache" using WampServer 2.0)
Open the service properties (double-click or right click->properties)
Flip to the Log On account and ensure the checkbox titled "Allow service to interact with Desktop" is checked
Flip back to the General tab, stop the service, start the service

以下是我为解决方案提出的问题的链接:php How do I start an external program running - Having trouble with system and exec

希望它可以帮助别人。