asynchronous system shell?

Discussion in 'Perl Misc' started by Ninja67, Apr 7, 2005.

  1. Ninja67

    Ninja67 Guest

    I have a perl script that is run on the web, that in turn, calls
    another external program.

    I can get the script to work, but the perl insists on waiting for the
    external program to complete before completing the script.

    The external program is not generating output that needs to be shown to
    the user and it can take up to 2 minutes to run which is too long to
    ask a web user to wait.

    How do I tell perl to execute an external program and not wait for it
    to complete before continuing with the perl?

    I'm running on an Apache server using Unix.

    Here's the code that launches the program...
    system ("$sas $home/$pname.sas -log $home/$pname.log -print
    $home/$pname.lst -sasuser $home -work $home >/dev/null 2>/dev/null");

    I'm thinking there must be an easy modification to this call to tell
    perl to keep on trucking.
    Ninja67, Apr 7, 2005
    #1
    1. Advertising

  2. "Ninja67" <> wrote in news:1112899846.301076.98830
    @f14g2000cwb.googlegroups.com:

    > I have a perl script that is run on the web, that in turn, calls
    > another external program.
    >
    > I can get the script to work, but the perl insists on waiting for the
    > external program to complete before completing the script.


    http://www.stonehenge.com/merlyn/LinuxMag/col39.html

    > How do I tell perl to execute an external program and not wait for it
    > to complete before continuing with the perl?
    >
    > I'm running on an Apache server using Unix.
    >
    > Here's the code that launches the program...
    > system ("$sas $home/$pname.sas -log $home/$pname.log -print
    > $home/$pname.lst -sasuser $home -work $home >/dev/null 2>/dev/null");


    That's a little scary, opening a behemoth like SAS to the whole wild
    world.

    perldoc perlsec

    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, Apr 7, 2005
    #2
    1. Advertising

  3. Ninja67

    Ninja67 Guest

    A. Sinan Unur wrote:
    > "Ninja67" <> wrote in news:1112899846.301076.98830
    > @f14g2000cwb.googlegroups.com:
    >
    > > I have a perl script that is run on the web, that in turn, calls
    > > another external program.
    > >
    > > I can get the script to work, but the perl insists on waiting for

    the
    > > external program to complete before completing the script.

    >
    > http://www.stonehenge.com/merlyn/LinuxMag/col39.html


    Wow, that's a lot of good information, but way over my head. The
    author of that page is showing how to keep track of a process that was
    launched, but I can't tell how he actually launches it. I'm fairly new
    to perl, so I probably just don't know what to look for. In my program
    though, I don't care when the externally called application finishes.
    I have no desire to monitor it whatsoever. I simply want to call it
    and let it go.

    > > How do I tell perl to execute an external program and not wait for

    it
    > > to complete before continuing with the perl?
    > >
    > > I'm running on an Apache server using Unix.
    > >
    > > Here's the code that launches the program...
    > > system ("$sas $home/$pname.sas -log $home/$pname.log -print
    > > $home/$pname.lst -sasuser $home -work $home >/dev/null

    2>/dev/null");
    >
    > That's a little scary, opening a behemoth like SAS to the whole wild
    > world.
    >
    > perldoc perlsec


    It would be, but the variables you see above have hard-coded values
    assigned at the beginning of the script. Also, this is on an internal
    company server not available on the internet.
    Ninja67, Apr 7, 2005
    #3
  4. Ninja67

    Guest

    "A. Sinan Unur" <> wrote:
    > "Ninja67" <> wrote in news:1112899846.301076.98830
    > @f14g2000cwb.googlegroups.com:
    >
    > > I have a perl script that is run on the web, that in turn, calls
    > > another external program.
    > >
    > > I can get the script to work, but the perl insists on waiting for the
    > > external program to complete before completing the script.


    Add an "&" to the end. see:
    perldoc -q background.

    > > Here's the code that launches the program...
    > > system ("$sas $home/$pname.sas -log $home/$pname.log -print
    > > $home/$pname.lst -sasuser $home -work $home >/dev/null 2>/dev/null");

    >
    > That's a little scary, opening a behemoth like SAS to the whole wild
    > world.


    Not all servers are open to the whole wild world.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Apr 7, 2005
    #4
  5. Ninja67

    Ninja67 Guest

    wrote:
    > "A. Sinan Unur" <> wrote:
    > > "Ninja67" <> wrote in news:1112899846.301076.98830
    > > @f14g2000cwb.googlegroups.com:
    > >
    > > > I have a perl script that is run on the web, that in turn, calls
    > > > another external program.
    > > >
    > > > I can get the script to work, but the perl insists on waiting for

    the
    > > > external program to complete before completing the script.

    >
    > Add an "&" to the end. see:
    > perldoc -q background.


    That worked! You're a genius! Now that sure was easy. I wonder why
    it was so hard to find anything on that.

    Thanks again!
    Ninja67, Apr 7, 2005
    #5
  6. Ninja67 wrote:
    > wrote:
    >> "A. Sinan Unur" <> wrote:
    >> Add an "&" to the end. see:
    >> perldoc -q background.

    >
    > That worked! You're a genius! Now that sure was easy. I wonder why
    > it was so hard to find anything on that.


    Because it has nothing to do with Perl (in Perl you would fork() and exec())
    but with how your shell starts processes in the background.

    jue
    Jürgen Exner, Apr 8, 2005
    #6
  7. Ninja67

    Joe Smith Guest

    Ninja67 wrote:

    >>Add an "&" to the end. see:
    >>perldoc -q background.

    >
    > That worked! You're a genius! Now that sure was easy. I wonder why
    > it was so hard to find anything on that.


    Hard to find?

    perldoc -f system
    system LIST
    Does exactly the same thing as "exec LIST", except that a fork
    is done first, and the parent process waits for the child pro-
    cess to complete. Note that argument processing varies depend-
    ing on the number of arguments. If there is more than one
    argument in LIST, or if LIST is an array with more than one
    value, starts the program given by the first element of the
    list with arguments given by the rest of the list. If there is
    only one scalar argument, the argument is checked for shell
    metacharacters, and if there are any, the entire argument is
    passed to the system's command shell for parsing (this is
    "/bin/sh -c" on Unix platforms, but varies on other platforms).

    That last line implies that you should look at the manual for the
    Bourne shell to see how /bin/sh will handle the LIST. Since you
    are using "2>/dev/null" is it obvious that you are at least
    somewhat familiar with Bourne shell metacharacters.

    -Joe
    Joe Smith, Apr 8, 2005
    #7
  8. Ninja67

    Ninja67 Guest

    Joe Smith wrote:
    > Ninja67 wrote:
    >
    > >>Add an "&" to the end. see:
    > >>perldoc -q background.

    > >
    > > That worked! You're a genius! Now that sure was easy. I wonder

    why
    > > it was so hard to find anything on that.

    >
    > Hard to find?
    >
    > perldoc -f system
    > system LIST
    > Does exactly the same thing as "exec LIST", except that a

    fork
    > is done first, and the parent process waits for the child

    pro-
    > cess to complete. Note that argument processing varies

    depend-
    > ing on the number of arguments. If there is more than one
    > argument in LIST, or if LIST is an array with more than one
    > value, starts the program given by the first element of the
    > list with arguments given by the rest of the list. If there

    is
    > only one scalar argument, the argument is checked for shell
    > metacharacters, and if there are any, the entire argument is
    > passed to the system's command shell for parsing (this is
    > "/bin/sh -c" on Unix platforms, but varies on other

    platforms).
    >
    > That last line implies that you should look at the manual for the
    > Bourne shell to see how /bin/sh will handle the LIST. Since you
    > are using "2>/dev/null" is it obvious that you are at least
    > somewhat familiar with Bourne shell metacharacters.
    >
    > -Joe


    Thanks Joe, that's great information. You made one incorrect
    assumption however. Although 99% of the perl script is written by me,
    the system call was inherited from another program. I have *no idea*
    what 2>/dev/null does. All I know is that without it, things weren't
    working so I left it in. I probably should research what that portion
    of the call actually means, but with other priorities in the way, I
    took a "it's not broke so don't fix it" approach.

    Thanks again.
    Ninja67, Apr 8, 2005
    #8
    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. Replies:
    2
    Views:
    5,653
    Jonathan Bromley
    Feb 18, 2005
  2. Christian Heimes
    Replies:
    0
    Views:
    583
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,058
    Philipp Pagel
    Feb 27, 2008
  4. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    843
    D'Arcy J.M. Cain
    Feb 27, 2008
  5. Samuel A. Falvo II
    Replies:
    0
    Views:
    472
    Samuel A. Falvo II
    Oct 8, 2008
Loading...

Share This Page