how to call exec multi-times...

J

Jianli Shen

Hi,

I write the following script,
hope it call "atouRcv -b ***** & " in each iteration.
however, it only call once when $port=6811

is that because: exec will not call the END block, nor will it call any
DESTROY method in the object ???

how can I make this loop work ??

Thanks


#!/usr/bin/perl

my $port=6811;
foreach my $r ( 0, 50, 200 ){
foreach my $l (0, 0.01, 0.05){
for (my $i=0; $i<=9; $i++) { #each run 10times
exec "atouRcv -b 2000000 -r ". $r . " -l ". $l . " -p " . $port . " &
";
$port += 1;
}
}
}
 
A

A. Sinan Unur

is that because: exec will not call the END block, nor will it call
any DESTROY method in the object ???

perldoc -f exec

exec LIST
exec PROGRAM LIST
The "exec" function executes a system command *and never
returns* ...

Read the documentation for more information.

Have you seen the posting guidelines for this group?

Sinan
 
J

Jianli Shen

Yes, I have read the perldoc,

is that put all the command to a command list then call exec ??

Thanks
 
J

Jürgen Exner

Jianli said:
I write the following script,
hope it call "atouRcv -b ***** & " in each iteration.

How would that be? The program that is started via "exec" _replaces_ your
Perl program.
After calling exec once there is nothing left that could possibly iterate
anything.
however, it only call once when $port=6811

Yeah, that's the documented behaviour of exec().
is that because: exec will not call the END block, nor will it call
any DESTROY method in the object ???

No, it is because a successful exec() never returns to begin with.
how can I make this loop work ??

Use the proper tool. Maybe you were looking for system() instead?

jue
 
J

John W. Krahn

Jianli said:
I write the following script,
hope it call "atouRcv -b ***** & " in each iteration.
however, it only call once when $port=6811

is that because: exec will not call the END block, nor will it call any
DESTROY method in the object ???

how can I make this loop work ??


#!/usr/bin/perl

my $port=6811;
foreach my $r ( 0, 50, 200 ){
foreach my $l (0, 0.01, 0.05){
for (my $i=0; $i<=9; $i++) { #each run 10times
exec "atouRcv -b 2000000 -r ". $r . " -l ". $l . " -p " . $port . " &
";
$port += 1;
}
}
}

Perhaps you want something like (UNTESTED):

#!/usr/bin/perl
use warnings;
use strict;

my $port = 6811;
for my $r ( 0, 50, 200 ) {
for my $l ( 0, 0.01, 0.05 ) {
for ( 1 .. 10 ) { # each run 10 times
defined( my $pid = fork ) or die "Cannot fork: $!";
$pid or exec 'atouRcv', '-b', 2000000, '-r', $r, '-l', $l, '-p', $port;
$port++;
}
}
}



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top