如何通过PHP执行批处理文件? [英] How to execute batch file via PHP?
问题描述
我试图在PHP中使用exec命令执行批处理文件. 我只是像这样使用它:
I tried to execute the batch file using exec command in PHP. I just used it like:
$filename = 'test.bat';
exec($filename);
但是没有得到任何输出.我用另一个命令尝试了此功能,效果很好. 您的建议将不胜感激. 谢谢
But didn't get any output. I tried this function with another command, it works fine. Your suggestions would be highly appreciated. Thanks
推荐答案
主要问题是path
和permission
.我已经执行了批处理文件.
The main issue was of path
and permission
. I have gotten my batch file to execute.
这是我的解决方案:
-
我从php文件所在的文件夹运行批处理文件.
I run my batch file from the same folder the php file is in.
exec("mybatch.bat");
我确保Apache Service具有足够的权限来运行批处理文件.为了测试,我使用Apache的管理员帐户登录.
I make sure that Apache Service has enough permission to run the batch file. Just to test i used an administrator account for Apache to log on with.
这篇关于如何通过PHP执行批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!