Page 1 of 1

help in invoking an external program

Posted: Mon Oct 23, 2006 5:47 am
by jasongr
Hello people

I have a PHP script that attempts to invoke an external shell command.
The shell command is an executable written in C++.
The executable program spawns a new thread which inokes PHP again using c:\php\php.exe and the original thread returns immediately to the call (the original PHP script)

here is what I expected to happen:
Script a.php invokes command shell:

Code: Select all

exec("c:\program.exe", $output, $returnValue);
program.exe spawn a new thread which invokes c:\php\php.exe on new script b.php
The orignal thread in program.exe shouldn't wait for b.php to complete (as this is a different thread), and immediately terminate, causing the code to return to a.php
so a.php continues to run while in the backgound, b.php is still running...

However, what is happening is that
the code doesn't return to a.php until b.php terminates.
I checked my program.exe code and it is flawless.
In fact, if I invoke program.exe directly from the command line, program.exe terminates immediately and b.php is running in the background...

I even tried using system instead of exe
In both cases, I get the same problem

any help would be appreicated

thanks

Posted: Mon Oct 23, 2006 7:39 am
by akimm
try uses a loop maybe

Code: Select all

while(condition1) {
exec("c:\program.exe", $output, $returnValue); 
}
or try a do-while loop?

Posted: Mon Oct 23, 2006 7:42 am
by jasongr
why would a loop help me?

I want the executable to be invoked just once. The problem is that the flow of the code is not resumed as soon as the executable is invoked

Posted: Mon Oct 23, 2006 7:56 am
by volka
Did you read the user contributed notes at http://de2.php.net/manual/en/function.exec.php ?
Some of them deal with background tasks under win32.

btw:
jasongr wrote:The orignal thread in program.exe shouldn't wait for b.php to complete (as this is a different thread)
Not thread, exec() create a new process.

Posted: Tue Oct 24, 2006 5:26 am
by jasongr
I solved the problem by using psExec
http://www.sysinternals.com/Utilities/PsExec.html