note 116419 added to function.exec

From: Date: Tue, 30 Dec 2014 14:25:50 +0000
Subject: note 116419 added to function.exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-201282@lists.php.net to get a copy of this message
Hi there, If you want to pass some parameters through $cmd in solution from "Arno van den Brink" under Windows, keep in mind that you should pass empty double quotes right after "start /B" or as first parameter of $cmd. Example: <?php function execInBackground($cmd) { if (substr(php_uname(), 0, 7) == "Windows"){ pclose(popen("start /B ". $cmd, "r")); } else { exec($cmd . " > /dev/null &"); } } ?> This code will open prj.php in default php editor: <?php $cmd = '"C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\Progr\Prj\scripts\prj.php"'; execInBackground($cmd) ; // full command is: // start /B "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\Progr\Prj\scripts\prj.php" ?> This happens because "start" parse first parameter as "title" (you can find more information in help for start command: "start /?") So you should put something, for example empty value in quotes before main command: <?php $cmd = '"" "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\Progr\Prj\scripts\prj.php"'; execInBackground($cmd); // full command is: // start /B "" "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\Progr\Prj\scripts\prj.php" ?> This code will open prj.php in notepad++ as expected. ---- Server IP: 72.52.91.14 Probable Submitter: 212.115.238.116 ---- Manual Page -- http://php.net/manual/en/function.exec.php Edit -- https://master.php.net/note/edit/116419 Del: integrated -- https://master.php.net/note/delete/116419/integrated Del: useless -- https://master.php.net/note/delete/116419/useless Del: bad code -- https://master.php.net/note/delete/116419/bad+code Del: spam -- https://master.php.net/note/delete/116419/spam Del: non-english -- https://master.php.net/note/delete/116419/non-english Del: in docs -- https://master.php.net/note/delete/116419/in+docs Del: other reasons-- https://master.php.net/note/delete/116419 Reject -- https://master.php.net/note/reject/116419 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201282) next »