List Info

Thread: Re: Running another exe program from Main Perl program without interupting




Re: Running another exe program from Main Perl program without interupting
country flaguser name
United States
2008-03-17 01:00:50

Thanks Sandy, Its working for me. But I am struggling to kill the
child process later from the main program. The following is the code I
used:

$| = 1;

if ($pid = fork) {
print "End of Parent";
$child_pid=$pid;
} else {

system ("newprogram.exe");
exit(0);
}

#Here I want to close the "newprogram.exe"
kill ($child_pid);

But the Killing is not working.

Thanks

Joshy

--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, "Alexander Saydakov"
<sandy_saydakov...> wrote:
&gt;
> --- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, "joshypy" <joshypy> wrote:
&gt; > I would like to run another (.exe) program from my perl main program
> > without any interrupting my main program.
> >
> > Right now I am using
> >
> > system(&quot;newprogram.exe&quot;);
> >
> > But for this my main program is waiting for the new program to get
> > closed. I still want my main program to continue while the
> > "newprogram.exe" is running.
>
> In other words, you want to fork off a child process.
>
> perldoc -f fork
>; perldoc perlfork
>
> /sandy
&gt; http://myperlquiz.com/
>

__._,_.___
.

__,_._,___
Re: Running another exe program from Main Perl program without interupting
country flaguser name
United States
2008-03-17 10:29:19

--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, "joshypy" <joshypy...> wrote:
&gt;
> Thanks Sandy, Its working for me. But I am struggling to kill the
> child process later from the main program. The following is the code I
> used:
&gt;
> $| = 1;
>
> if ($pid = fork) {
> print "End of Parent&quot;;
> $child_pid=$pid;
&gt; } else {
>
> system ("newprogram.exe");
> exit(0);

I would try calling exec() instead of system() here. system()
introduces one more level of parent-child, which is an unnecessary
complexity here.

> }
>
> #Here I want to close the "newprogram.exe"
&gt; kill ($child_pid);

I am not sure why do you want to kill it. You want the parent and the
child to do something in parallel, don't you? And when the parent is
done, you probably want it to wait for the child.

perldoc -f wait
perldoc -f waitpid

/sandy
http://myperlquiz.com/

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )