Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

don't wait for system calls 1

Status
Not open for further replies.

bardley

Programmer
May 8, 2001
121
US
Sorry if there is another thread about this--I looked briefly for one.

Is there a way to make a system call (in Windows, if it matters) such that the Perl script doesn't wait for that call to end?

For example:
`ping hostname`;
waits for the DOS command to finish before the script continues, but I want it not to do that.

Thanks all! Brad Gunsalus
Cymtec Systems, Inc.
bgunsalus@cymtec.com
 
there is another thread, fairly recently, but not very well named.
the answer i gave there was to open a pipe - a filehandle opened on a command which is followed by a '|', or pipe symbol. here's how this would look:[tt]
open PIPE, "command |";
[/tt]
then you treat this like a filehandle you opened for reading from and you can get the data it outputs:[tt]
while (<PIPE>)
{
print;
}[/tt]

or you can read it one line at a time, or read it into an array for manipulation. whatever you do, your program won't wait for the process until you actively try to read from it, but that allows for more flexability with what gets done when within your program. &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Yes - you can use the fork() function, if your version of perl supports fork() on windows that is. Check your documentation.

if(my $cpid=fork()){
# then I am the parent, I can carry on just fine
[tab]print &quot;child process launched, pid=$cpid\n&quot;;
} else {
# then I am the child process
# do some work
[tab]system(&quot;some_command&quot;);
# and then just the child process can exit
[tab]exit 0;
}

# I am the parent here as well
# parent process exits
exit 0;
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top