note 53997 modified in function.popen by danbrown

From: Date: Mon, 02 Mar 2009 13:37:24 +0000
Subject: note 53997 modified in function.popen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151331@lists.php.net to get a copy of this message
If you want to fork a process under windows, this is the function to use. I created a batch file called runcmd.bat with the following line start %1 %2 %3 %4 then I have the folowing function <?php define('RUNCMDPATH', 'c:\\htdocs\\nonwebspace\\runcmd.bat'); function runCmd($cmd) { $externalProcess=popen(RUNCMDPATH.' '.$cmd, 'r'); pclose($externalProcess); } ?> with this, doing something like <?php runCmd('php.exe printWorkOrder.php 3498'); ?> will launch php.exe outside of apache and allow the script calling the runCmd() function to continue without waiting for the command line process to return. The process will run under the same user account that Apache (or whatever webserver you're running) is running under, so make sure it has permissions to do whatever you need to do. Also, make sure that the batch file has enough %n s in order to pass all the command line variables that you might need to pass. Special thanks to kicken from the devshed forums for coming up with the idea. --was-- If you want to fork a process under windows, this is the function to use. I created a batch file called runcmd.bat with the following line start %1 %2 %3 %4 then I have the folowing function <? define('RUNCMDPATH', 'c:\\htdocs\\nonwebspace\\runcmd.bat'); function runCmd($cmd) { $externalProcess=popen(RUNCMDPATH.' '.$cmd, 'r'); pclose($externalProcess); } ?> with this, doing something like <? runCmd('php.exe printWorkOrder.php 3498'); ?> will launch php.exe outside of apache and allow the script calling the runCmd() function to continue without waiting for the command line process to return. The process will run under the same user account that Apache (or whatever webserver you're running) is running under, so make sure it has permissions to do whatever you need to do. Also, make sure that the batch file has enough %n s in order to pass all the command line variables that you might need to pass. Special thanks to kicken from the devshed forums for coming up with the idea. http://php.net/manual/en/function.popen.php

« previous php.notes (#151331) next »