Reputation: 721
I'm trying to do this:
system("cmd /c C:\test.txt");
I already tried exec("C:\test.txt")
, exec('"C:\test.txt"')
, but nothing is working, some tries the script only keeps loading and some tries he loads but no returns! I'm thinking that is permissions problem..
Upvotes: 2
Views: 3936
Reputation: 1045
You can create a .bat file and use this:
openfile.bat
start notepad "myfile.txt"
"myshortcut.lnk"
exit
PHP
exec("C:\openfile.bat")
Source: Open text file and program shortcut in Windows batch file
EDIT Unfortunately i cant test this right now but if you want the process to run in the background this might do the trick in both windows and 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);
source: http://www.php.net/manual/en/function.exec.php
also try:
exec("start /B C:\openfile.bat");
and I found an other stack question regaring the same: How do you run a .bat file from PHP?
Upvotes: 4