【问题标题】:Cannot Execute .bat file in PHP wamp无法在 PHP wamp 中执行 .bat 文件
【发布时间】:2017-04-27 06:01:34
【问题描述】:

我在我的 php 文件的同一个文件夹中运行我的文件,并且我使用 Apache 的管理员帐户登录。 这是我的代码: <?php exec("testbat.bat"); ?>

【问题讨论】:

  • 是否启用了安全模式? shell_exec 在安全模式下被禁用。另外,如果上面没问题,如果您还没有检查错误日志,请先检查您的 Apache/php 错误日志。
  • 页面只是在浏览器上显示一个加载标志,从不加载。
  • php.net/manual/en/function.exec.php 可能会有所帮助
  • @JoshulSharma 安全模式已关闭
  • @Yang,请参考:php.net/manual/en/function.exec.php:查看备注部分。

标签: php html apache wamp


【解决方案1】:

创建一个文件并将其保存为 filename.bat

这是一个例子

批处理文件名为test.bat

@echo Hello Houssem...

@pause

之后从 php 文件“executeme.php”调用它

//to execute the bat file directly 
exec('c:\WINDOWS\system32\cmd.exe /c START test.bat');

// OR to read Only the content of the batch file 

// the bat file label
$batname = "test.bat" ; 

$output = exec("c:\\windows\\system32\\cmd.exe /c $batname"); 

echo $output  ;

【讨论】:

  • 谢谢,我现在就试试。
  • 它写“等待本地主机”,它只是不加载
  • 使用另一个本地网络服务器,如 Wamp - XAMPP ,或检查 cmd.exe 的目录
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-25
  • 1970-01-01
  • 2010-12-25
  • 2015-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多