note 110131 deleted from function.exec by tularis

From: Date: Sun, 01 Dec 2013 16:05:55 +0000
Subject: note 110131 deleted from function.exec by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197686@lists.php.net to get a copy of this message
Note Submitter: wouter99999 at gmail dot com ---- To run your command in the background on Windows, you have to use start /B before your command (in Linux add & after your command). exec() simply uses cmd /C. The /C carries out the command specified by the string and then terminates. However start /B needs to be put before that, so you cannot use exec() for running a command in the background on Windows. Instead use popen. Example: pclose(popen('start /B php yourscript.php > result.txt 2> error.log', 'r')); works. But what if you have spaces in your filenames? Escape them with double quotes: pclose(popen('start /B php "your script.php" > "my result.txt" 2> "error.log"' , 'r')); works. But now let's assume that you do not have php in your path. This does not work: pclose(popen('start /B "C:\Program Files (x86)\PHP\php.exe" "your script.php" > "my result.txt" 2> "error.log"' , 'r')); Why? Because cmd only preserves the double quotes if there is not one of: &<>()@^| special characters between the two double-quote characters. Double quotes between double quotes are preserved however if /S is used, in that case only the two outer double quotes are removed. So add two double quotes surrounding your command and add the default cmd /C plus the extra /S like: pclose(popen('start /B cmd /S /C ""C:\Program Files (x86)\PHP\php.exe" "your script.php" > "my result.txt" 2> "error.log""' , 'r'));

« previous php.notes (#197686) next »