From: "John W. Krahn" <[EMAIL PROTECTED]>
> "Daryl J. Hoyt" wrote:
> > I have a problem I can not seem to figure out. I need run an
> > executable
> > from a Perl script and I want it to return the PID for the
> > executable. I looked at the docs for fork(), but if I did something
> > like: if($PID = fork) {
> > system("foo.exe");
> > }
> > I think it would return the PID for the fork in the if statement and
> > not the one from the system call. Is there any way to get the PID
> > from the child? Any help would be greatly appreciated.
>
> The problem is that system() forks as well. Use exec() and the PID
> returned from fork() will be the PID that "foo.exe" is running as.
This would work under Unix, but it does not under Win32.
The fork creates a thread, not a new process and the exec() then
creates the process and closes the thread. Therefore the fork()
returns a thread id, not a process id.
This should be the way:
$pid = system( 1, "foo.exe");
Notice the first parameter to system(). It tells the function to
start the process in background and not to wait for it. Therefore
instead of exit code it returns the pid.
Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]