php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30794 exec hangs until program is over
Submitted: 2004-11-15 14:47 UTC Modified: 2005-03-06 19:16 UTC
Votes:25
Avg. Score:4.3 ± 0.8
Reproduced:21 of 22 (95.5%)
Same Version:11 (52.4%)
Same OS:11 (52.4%)
From: stolle at web dot de Assigned:
Status: Wont fix Package: Program Execution
PHP Version: 5.0.2 OS: Windows XP SP2
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-11-15 14:47 UTC] stolle at web dot de
Description:
------------
I'm using PHP on Apache2 (both: Latest Builds)

When starting a Program using "exec()" die PHP-Scripts allways hangs under Windows, until the started program terminates.

There is no chance to start f.e. notepad.exe in that way, that notepad runs interaktivly, but PHP continous work.

Notepad is just an example, i want to control (start and stop) some Windows-Tasks throug PHP.

I tried the latest PHP snapshot-Version as well.

Reproduce code:
---------------
    exec('notepad.exe');

    exec( "cmd.exe /c c:/windows/notepad.exe 2>nul: >nul:" );


    exec( "c:/windows/notepad.exe 2>nul: >nul: &" );

    exec( "c:/windows/notepad.exe 2>nul: >nul:" );


Expected result:
----------------
PHP Script should NOT wait for end of notepad

Actual result:
--------------
PHP Script wait's for end of notepad

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-15 16:54 UTC] tony2001@php.net
I don't see any bugs here. It's pretty well expected behaviour.
The docs say: "If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends."
But your program *waits for your input* (i.e. until you close it), so PHP will wait for it too, 'cause exec() "returns the last line from the result of the command" (c).
 [2004-11-15 21:36 UTC] stolle at web dot de
you have to make sure that the
output of that program is redirected to a file or some other output
stream or else PHP will hang until the execution of the program ends."

So the right question may be: How do i redirect the standardoutput under Windows, so that PHP do NOT wait fpr the end of the Programm.

I tried som more lines:
    exec( "cmd.exe /c start c:/windows/notepad.exe <nul: 2>nul: >nul:" );

    exec( "c:/windows/notepad.exe <nul: 2>nul: >nul:" );

It's always the same: PHP always wait's for notepad's end. BUT I DONT WANT TO WAIT! 
What do i have to do (under windows) to not wait for the end of the program ???
 [2004-11-15 21:42 UTC] stolle at web dot de
It seems to be so, that PHP wait's for the last process of the group of child processes to terminate.
Is there any way (in PHP) to break that behavour?
 [2004-11-15 21:43 UTC] stolle at web dot de
Reopened
 [2004-11-19 10:53 UTC] stolle at web dot de
So the right question may be: How do i redirect the standardoutput under
Windows, so that PHP does NOT wait for the end of the Programm.

I tried some more lines:
    exec( "cmd.exe /c start c:/windows/notepad.exe <nul: 2>nul: >nul:"
);

    exec( "c:/windows/notepad.exe <nul: 2>nul: >nul:" );

It's always the same: PHP always wait's for notepad's end. BUT I DON'T WANT TO WAIT! 
What do i have to do (under windows) to not wait for the end of the
program ???
 [2004-12-05 17:14 UTC] mvel at centrum dot cz
Hi,

I was the same problem. No one of these below has effect. Like my English :-).

exec('cmd /C "ping 147.32.x.x -t"');
exec('cmd /C "start ping 147.32.x.x -t"');
exec('cmd /C "pingIP.bat"');
exec('cmd /C "start pingIP.bat"');
content of pingIP.bat
ping 147.32.x.x -t or cmd /c 147.32.x.x -t or cmd /c 147.32.x.x -t 

so

<?php
$fp=popen("start InstallLinux.exe","r");
pclose($fp);
echo "Hastalavista Gates";
?>
Why "r" and not "w"? I dont know. "r" was in the manual. I think, it is much of a muchness.

wella
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Sep 16 04:01:26 2019 UTC