如何通过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

主要问题是pathpermission.我已经执行了批处理文件.

The main issue was of path and permission. I have gotten my batch file to execute.

这是我的解决方案:

  1. 我从php文件所在的文件夹运行批处理文件.

  1. 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.