note 59361 added to ref.exec

From: Date: Sun, 04 Dec 2005 16:50:37 +0000
Subject: note 59361 added to ref.exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-99556@lists.php.net to get a copy of this message
Starting batch or exe files (from a local Apache server 1.3.24 with PHP 4.3.1) to be executed within WinXP SP2 and having the program running in background - which certainly is tricky. I figured this peace of code makes it very possible. Instead of using exec() I prefered popen() adding the parameter /b which makes it run in the background, thus having PHP script continued to be interpreted contrary to be hanging in the process. <?php function callTool ($path,$file) { chdir($path); $call = $path.$file; pclose(popen('start /b '.$call.'', 'r')); } // -- Call tool1 ----- $location = "c:\path\to\desired\folder"; $filename = "\tool1.exe"; callTool($location,$filename); // -- Call tool2 ----- $location = "c:\path\to\desired\folder"; $filename = "\tool2.bat"; callTool($location,$filename); // -- Call tool3 ----- $location = "c:\path\to\desired\folder"; $filename = "\tool3.com"; callTool($location,$filename); ?> This example assumes that the Apache properties locally has bin told to 'allowe this server to interact with desktop' which on WinXP is to be set under Start > Run > services.msc - next, right click "Apache...", select properties and click on the 'login tab'. Hope someone to benefit out of this stuff. ---- Manual Page -- http://www.php.net/manual/en/ref.exec.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59361 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59361&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59361&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59361&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59361&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59361&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59361&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59361&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59361&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#99556) next »