how to call exec multi-times...

Discussion in 'Perl Misc' started by Jianli Shen, Sep 21, 2005.

  1. Jianli Shen

    Jianli Shen Guest

    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;
    }
    }
    }
     
    Jianli Shen, Sep 21, 2005
    #1
    1. Advertising

  2. "Jianli Shen" <> wrote in
    news:dgqnvp$mgj$:

    > 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
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Sep 21, 2005
    #2
    1. Advertising

  3. Jianli Shen

    Jianli Shen Guest

    Yes, I have read the perldoc,

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

    Thanks


    "A. Sinan Unur" <> wrote in message
    news:Xns96D88B1952B2asu1cornelledu@127.0.0.1...
    > "Jianli Shen" <> wrote in
    > news:dgqnvp$mgj$:
    >
    >> 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
    > --
    > A. Sinan Unur <>
    > (reverse each component and remove .invalid for email address)
    >
    > comp.lang.perl.misc guidelines on the WWW:
    > http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    Jianli Shen, Sep 21, 2005
    #3
  4. Jianli Shen wrote:
    > 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ürgen Exner, Sep 21, 2005
    #4
  5. Jianli Shen wrote:
    >
    > 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
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Sep 21, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hal Vaughan
    Replies:
    11
    Views:
    1,195
    Gordon Beaton
    May 22, 2006
  2. tedsuzman
    Replies:
    2
    Views:
    7,164
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  3. Ted
    Replies:
    1
    Views:
    494
    Duncan Booth
    Jul 22, 2004
  4. Guillermo Riojas
    Replies:
    0
    Views:
    198
    Guillermo Riojas
    Nov 26, 2010
  5. Random Task
    Replies:
    12
    Views:
    725
    Joe Smith
    Dec 4, 2005
Loading...

Share This Page