For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2006 > survive with exec









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author survive with exec
A B

2006-02-27, 6:58 pm

Hello ,

i want to execute some batch/perl file from my perl program and continue to
do some changes and then re-execute some files.

my code is like
st.pl
-------------
exec ("wperl hang.pl >a.txt");
exec ("wperl hang.pl >b.txt");
exec ("wperl hang.pl >c.txt");

hang.pl
-----------------

#!/usr/bin/perl
$a=1;
while($a)
{
$a=1;
}

Here i want to execute one and then execute another but don't wait for
previous command i.e.something in background but im unable to do it.

any idea ???



Thanks

a b

Jeff Pang

2006-02-27, 6:58 pm



>exec ("wperl hang.pl >a.txt");
>exec ("wperl hang.pl >b.txt");
>exec ("wperl hang.pl >c.txt");
>


hi,
here I think you could fork the childs,and call the 'exec' in childs,it should be good for your purpose.
for example,

for (my $i=0;$i<3;$i++){
my $child = fork();die "can't fork $!" unless defined $child;
exec ("wperl hang.pl >$i.txt") unless $child;
}


hope this help.


--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com
Jeff Pang

2006-02-27, 6:58 pm


>exec ("wperl hang.pl >a.txt");
>exec ("wperl hang.pl >b.txt");
>exec ("wperl hang.pl >c.txt");


and,I'm a little strange here. if your first 'exec' is executed successfully,the main script process should be replaced with the exec call.In other words,the executing of 'wperl hang.pl >a.txt' should replace the main code,and the 'exec' should never retu
rn unless its execution get failed.So,if the first 'exec' is executed successfully,the second and the third 'exec' should NEVER get executed at all.

--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com
Timothy Johnson

2006-02-27, 6:58 pm


What operating system are you running, and how important is the return
code to you?

If you are using Windows, for example, you can use the start or call
commands along with system() to spawn a process and immediately return.
The only problem is that you won't be able to check the return code,
because it will only indicate whether or not the shell was able to
execute the program.



-----Original Message-----
From: a b [mailto:testabhi@gmail.com]=20
Sent: Monday, February 27, 2006 5:01 AM
To: beginners@perl.org
Subject: survive with exec

Hello ,

i want to execute some batch/perl file from my perl program and continue
to
do some changes and then re-execute some files.

my code is like
st.pl
-------------
exec ("wperl hang.pl >a.txt");
exec ("wperl hang.pl >b.txt");
exec ("wperl hang.pl >c.txt");

hang.pl
-----------------

#!/usr/bin/perl
$a=3D1;
while($a)
{
$a=3D1;
}

Here i want to execute one and then execute another but don't wait for
previous command i.e.something in background but im unable to do it.

any idea ???



Thanks

a b

A B

2006-02-28, 3:56 am

Hello,

The Os was windows and use of start along with system is working fine.

Thanks & Regards
a b

On 2/28/06, Timothy Johnson <tjohnson@zonelabs.com> wrote:
>
>
> What operating system are you running, and how important is the return
> code to you?
>
> If you are using Windows, for example, you can use the start or call
> commands along with system() to spawn a process and immediately return.
> The only problem is that you won't be able to check the return code,
> because it will only indicate whether or not the shell was able to
> execute the program.
>
>
>
> -----Original Message-----
> From: a b [mailto:testabhi@gmail.com]
> Sent: Monday, February 27, 2006 5:01 AM
> To: beginners@perl.org
> Subject: survive with exec
>
> Hello ,
>
> i want to execute some batch/perl file from my perl program and continue
> to
> do some changes and then re-execute some files.
>
> my code is like
> st.pl
> -------------
> exec ("wperl hang.pl >a.txt");
> exec ("wperl hang.pl >b.txt");
> exec ("wperl hang.pl >c.txt");
>
> hang.pl
> -----------------
>
> #!/usr/bin/perl
> $a=1;
> while($a)
> {
> $a=1;
> }
>
> Here i want to execute one and then execute another but don't wait for
> previous command i.e.something in background but im unable to do it.
>
> any idea ???
>
>
>
> Thanks
>
> a b
>
>


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com