繁体   English   中英

从PHP脚本执行批处理文件(.bat)

[英]Execute a Batch File (.bat) from a PHP script

我有一个PHP代码,用于从加密狗发送SMS。 它只接受两个参数。 电话号码和消息,并将其传递到.bat文件。

$phoneNo = +1234567890;

$SMSMesseage = "your message";
$SMSMsg = "\"$SMSMesseage\"";

exec("sendsms.bat $phoneNo $SMSMsg");

我正在使用Gammu工具配置并通过加密狗发送短信。 因此.bat文件包含以下代码'

echo on
::
echo
::
cd C:\<installation_path>\Gammu 1.33.0\bin
set phnNo=%1
set msg=%2

gammu -c smsdrc
gammu -c smsdrc --sendsms TEXT %phnNo% -text %msg%

所以,我的问题是,当我通过网络浏览器访问sendSmsPhp.php时,它发送的短信没有任何问题。 但是,当我尝试使其作为Windows任务计划程序时,它无法正常工作。

我试图使用下面的命令通过命令提示符直接执行php脚本;

c:\<path_to_xampp>\xampp\php\php.exe -f c:\<path_to_xampp>\xampp\htdocs\LIMS_15\sendSmsPhp.php

但是它返回了;

'sendsms.bat' is not recognized as an internal or external command, operable program or batch file.

有什么办法可以实现?

您需要告诉cmd运行批处理文件

exec("cmd sendsms.bat $phoneNo $SMSMsg");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM