Executing multiple System Commands parallel

Discussion in 'Perl Misc' started by Tobias Glasow, Jul 22, 2004.

  1. Hi all,

    i want to execute multiple system commands at the same time out of a perl
    script. i tried exec, system an qx, but all seem to execute on command by
    one, after the preceding has finished.

    any ideas how to do this in perl?

    Tobias
    Tobias Glasow, Jul 22, 2004
    #1
    1. Advertising

  2. Tobias Glasow wrote:

    > Hi all,
    >
    > i want to execute multiple system commands at the same time out of a perl
    > script. i tried exec, system an qx, but all seem to execute on command by
    > one, after the preceding has finished.
    >
    > any ideas how to do this in perl?
    >
    > Tobias


    system("/path/to/command1 &");
    system("/path/to/command2 &");
    system("/path/to/command3 &");
    etc

    gtoomey
    Gregory Toomey, Jul 22, 2004
    #2
    1. Advertising

  3. Tobias Glasow wrote:
    > i want to execute multiple system commands at the same time out of a
    > perl script. i tried exec, system an qx, but all seem to execute on
    > command by one, after the preceding has finished.


    "At the same time" as in "in parallel"?
    Either use fork() to create multiple processes and each process launches its
    own system() or use whatever method your OS or shell (you didn't tell us)
    provides to launch each individual external command in the background, such
    that the next one will be started by the shell/OS before the preceeding
    commands are finished.

    jue
    Jürgen Exner, Jul 22, 2004
    #3
  4. Tobias Glasow

    Graham Wood Guest

    Tobias Glasow wrote:
    > Hi all,
    >
    > i want to execute multiple system commands at the same time out of a perl
    > script. i tried exec, system an qx, but all seem to execute on command by
    > one, after the preceding has finished.
    >
    > any ideas how to do this in perl?
    >
    > Tobias
    >
    >


    If you're on Windows, you can use the Win32::process module to create
    "forked" processes. If using ActiveState perl you get this for free and
    you don't even have to install it. "perldoc Win32::process" will show
    you the docs. Last time I checked fork() didn't work very well on
    Windows (it might now). If you're on Unix fork() is the man for the job.

    Graham
    Graham Wood, Jul 22, 2004
    #4
  5. >
    > system("/path/to/command1 &");
    > system("/path/to/command2 &");
    > system("/path/to/command3 &");
    > etc


    This does not work on Windows, of course.


    --
    Andre

    ---

    Fighting for peace is like f..ing for virginity
    Andre Wisniewski, Jul 22, 2004
    #5
  6. "Andre Wisniewski" <> wrote in
    news:eek:psbjwbez8udlqzq@helena:

    >> system("/path/to/command1 &");
    >> system("/path/to/command2 &");
    >> system("/path/to/command3 &");
    >> etc

    >
    > This does not work on Windows, of course.


    start can be used to achieve a similar effect.

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
    A. Sinan Unur, Jul 22, 2004
    #6
  7. >
    > start can be used to achieve a similar effect.
    >


    Yep.

    --
    Andre

    ---

    Fighting for peace is like f..ing for virginity
    Andre Wisniewski, Jul 22, 2004
    #7
    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. twsnnva
    Replies:
    6
    Views:
    939
    Cliff Wells
    Sep 11, 2004
  2. Soren
    Replies:
    4
    Views:
    1,250
    c d saunter
    Feb 14, 2008
  3. gravi2020
    Replies:
    0
    Views:
    1,805
    gravi2020
    Jan 15, 2009
  4. Vivek Menon
    Replies:
    5
    Views:
    3,336
    Paul Uiterlinden
    Jun 8, 2011
  5. vhaerun vh
    Replies:
    16
    Views:
    280
    Eleanor McHugh
    Sep 8, 2009
Loading...

Share This Page