从PHP脚本执行批处理文件(.bat)
问题描述:
我有一个php代码可以从加密狗发送短信。它只需要两个参数;电话号码&的消息并将其传递给.bat文件。从PHP脚本执行批处理文件(.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%
所以,我的问题是,当我通过Web浏览器访问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");
+0
我做了修改,并没有奏效。当我在命令提示符下直接尝试时,它没有返回任何东西。 – Buddika
+0
然后,我很抱歉,我无法提供任何更多的建议。 :) –
你可以把所有的代码在bat文件在PHP – 2016-03-08 03:27:23