我正在尝试这样做:system("cmd /c C:'test.txt");
我已经尝试了exec("C:'test.txt")
、exec('"C:'test.txt"')
,但什么都不起作用,有些尝试脚本只持续加载,有些尝试他加载但没有返回!我认为这是权限问题。。
您可以创建一个.bat文件并使用它:
openfile.bat
start notepad "myfile.txt"
"myshortcut.lnk"
exit
PHP
exec("C:'openfile.bat")
来源:在Windows批处理文件中打开文本文件和程序快捷方式
编辑不幸的是,我现在无法测试,但如果你想让进程在后台运行,这可能会在windows和linux中都起作用:
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
execInBackground(start /B openfile.bat);
来源:http://www.php.net/manual/en/function.exec.php
也可以尝试:
exec("start /B C:'openfile.bat");
我发现了另一个同样的堆栈问题:如何从PHP运行.bat文件?