Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > asynchronous system shell?

Reply
Thread Tools

asynchronous system shell?

 
 
Ninja67
Guest
Posts: n/a
 
      04-07-2005
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.

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-07-2005
"Ninja67" <(E-Mail Removed)> 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 <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
 
Ninja67
Guest
Posts: n/a
 
      04-07-2005

A. Sinan Unur wrote:
> "Ninja67" <(E-Mail Removed)> 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.

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-07-2005
"A. Sinan Unur" <(E-Mail Removed)> wrote:
> "Ninja67" <(E-Mail Removed)> 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
 
Reply With Quote
 
Ninja67
Guest
Posts: n/a
 
      04-07-2005

(E-Mail Removed) wrote:
> "A. Sinan Unur" <(E-Mail Removed)> wrote:
> > "Ninja67" <(E-Mail Removed)> 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!

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      04-08-2005
Ninja67 wrote:
> (E-Mail Removed) wrote:
>> "A. Sinan Unur" <(E-Mail Removed)> 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


 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      04-08-2005
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
 
Reply With Quote
 
Ninja67
Guest
Posts: n/a
 
      04-08-2005

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make the system.process as asynchronous from asp.net page button click event? Ritha Software 0 09-29-2009 07:17 AM
System.Security.SecurityException: Error de solicitud de permiso de tipo System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Luis Esteban Valencia ASP .Net 0 07-14-2005 01:43 PM
Coding an Asynchronous state machine Jamie VHDL 13 10-23-2003 08:41 AM
Send a PULSE on input change, asynchronous Jamie VHDL 4 10-22-2003 06:57 AM
asynchronous design Amir VHDL 3 10-10-2003 02:10 PM



Advertisments