如何通过PHP执行批处理文件?

Nik*_* K. 5 php command-line batch-file exec

我尝试在PHP中使用exec命令执行批处理文件.我只是用它:

$filename = 'test.bat';
exec($filename);
Run Code Online (Sandbox Code Playgroud)

但没有得到任何输出.我用另一个命令尝试了这个功能,它运行正常.您的建议将受到高度赞赏.谢谢

Nik*_* K. 7

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

这是我的解决方案:

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

    exec("mybatch.bat");

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

  • 正确的解决方案,Batch文件和php文件都在同一个文件夹中 (2认同)