Re: note 25599 rejected from function.exec by betz
| From: | MWCT - Markus Weber | Date: | Wed, 02 Oct 2002 10:00:44 +0000 |
| Subject: | Re: note 25599 rejected from function.exec by betz | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-16126@lists.php.net to get a copy of this message | ||
<betz@php.net> schrieb im Newsbeitrag
news:20020929234459.13911.qmail@rack1.php.net...
> I am running a WIMP configuration and I want to use exec() to call
mysql.exe via my PHP script to run a big sql script in the background. The
PHP script executes the sql script via mysql.exe but my PHP script hangs
until the mysql process has finished. Does anybody know how I can run the
exec() command totally in the background on a WIMP system ? (I tried a lot
with "2>1&" and "cmd/c" etc.)
------------------------------------------
Please read this from letterj@Phpgeek.com:
Mwct - Markus Weber wrote:
> Hi,
>
> may be someone can help me:
>
> I want to use the exec() function to run an executable as background
> process. This means my php script should not wait for the end of the
> background process. I tried a lot but without success. My script always
wait
> for the end of the background process.
>
> My php script contains this line:
>
> exec(getenv("COMSPEC").' /c c:\mysql\bin\mysql.exe <
> E:/Inetpub/wwwroot/update/load_logs.sql >
> E:/Inetpub/wwwroot/update/load_logs.log');
>
> Regarding to the online documentation on php.net all screen output is
> redirected to the file "load_logs.log".
>
> When I type in this string via command line the execution is successful.
>
> As I learned from the online documentation on php.net is that on LINUX
> systems something like "2>1&" or ">/dev/null" will help - but not
> on
> Windows.
>
> Any ideas ?
If this script will only ever be run on Windows servers, you can use the
Windows-specific shell capabilities through the COM interface.
$shell = new COM("WScript.Shell") or die("This thing requires Windows
Scripting Host");
$shell -> Run($commandinquotes,$windowstate,$wait);
Replace $commandinquotes with your commandline that you want to run. Put
it in single quotes. Replace $windowstate with 1, 2 or 3 for normal DOS
window, minimized or maximized and $wait with 0 in your case because you
don't want PHP to wait for the process to finish.
You could abstract it further by turning the COM "Run" into your own
function. The below code hasn't been tested.
function win_exec($command, $windowstate, $wait) {
$shell = new COM("WScript.Shell") or die("This thing requires Windows
Scripting Host");
$shell -> Run($commandinquotes,$windowstate,$wait);
}
$command = getenv("COMSPEC").' /c c:\mysql\bin\mysql.exe <
> E:/Inetpub/wwwroot/update/load_logs.sql >
> E:/Inetpub/wwwroot/update/load_logs.log';
win_exec($command, "2", "0");