作者LaPass (LaPass)
看板PHP
标题Re: [请益] 执行exe问题
时间Thu Feb 13 12:43:51 2014
※ 引述《forptt (上线专用)》之铭言:
: 我用exec()执行"C:\test\test.exe"
: 都没反应。
: 後来改用
: $cmd = "C:\test\test.exe";
: if (substr(php_uname(), 0, 7) == "Windows"){
: pclose(popen("start /B ". $cmd, "r"));
: }
: else {
: exec($cmd . " > /dev/null &");
: }
: 就能成功执行了。
: 但是把test.exe搬移位置并把$cmd路径改成$cmd = "c:\Program Files\test\test.exe"
: 就一直出现can not find "c:\Program" 的错误讯息,
: 我确认档案路径没错。
: 2个问题请教:
: 1. 怎麽顺利用exec()成功执行.exe档案
: 2. 我觉得是函式路径出现空白字元的问题
: 烦请好心大大帮我解答一下
: 谢谢
$cmd = "c:\Program Files\test\test.exe";
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
//等於
//exec("C:\Program Files\test\test.exe > /dev/null &");
//请注意空白
}
改成
exec(escapeshellarg($cmd) . " > /dev/null &");
应该就可以了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.163.219.211
※ 编辑: LaPass 来自: 118.163.219.211 (02/13 12:46)
1F:推 forptt:仍然不行呢~谢谢 02/13 13:35
2F:推 rickysu:$cmd = "c:\\Program Files\\test\\test.exe"; 02/13 13:54
3F:推 forptt:没办法呢~一直出现Can not find Program....的错误讯息 02/13 14:24