Windows: Fork and run a process in the background

2006-06-06 Thread Daniel Kasak
Greetings.

I'd like to trigger an application to open ( Acrobat Reader ), and *not*
freeze my perl app while it's open.
Under Linux, I do:

system ( evince /path/to/pdf.pdf  );

The ampersand does what I need. This doesn't work under Windows. Is
there a cheap  nasty workaround?

-- 
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Windows: Fork and run a process in the background

2006-06-06 Thread Timothy Johnson

Try this:

system( start evince /path/to/pdf.pdf );

Both cheap and nasty.

-Original Message-
From: Daniel Kasak [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 06, 2006 5:37 PM
To: beginners@perl.org
Subject: Windows: Fork and run a process in the background

Greetings.

I'd like to trigger an application to open ( Acrobat Reader ), and *not*
freeze my perl app while it's open.
Under Linux, I do:

system ( evince /path/to/pdf.pdf  );

The ampersand does what I need. This doesn't work under Windows. Is
there a cheap  nasty workaround?

-- 
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Windows: Fork and run a process in the background

2006-06-06 Thread Daniel Kasak
Timothy Johnson wrote:

 Try this:

   system( start evince /path/to/pdf.pdf );

 Both cheap and nasty.
   

That does it. Thanks :)

-- 
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Run a process in the background

2004-09-22 Thread Errin Larsen
Hi Perlers,

I know that questions like this get asked all the time, but I guess
it's just my turn to ask 'em!

I need to kick of some processes in my script.  However, the script
needs to kick them all off at once and then stick around to do some
other things.  I'm kinda new to Perl, but in my OS's shell, I'd do
this (actually, I DO do this ... this Perl script will be replacing
this shell script):

#!/bin/sh
nohup /path/to/process/one/bin/server.sh /dev/null 21 
nohup /path/to/process/two/bin/server.sh /dev/null 21 
nohup /path/to/process/three/bin/server.sh /dev/null 21 

I figure I can pass that string directly to system() in Perl, 

  system nohup /path/to/process/one/bin/server.sh /dev/null 21 ;
  system nohup /path/to/process/two/bin/server.sh /dev/null 21 ;
  system nohup /path/to/process/three/bin/server.sh /dev/null 21 ;

but that invokes the shell, right?  Also, I'd like to capture the
Process ID of those 3 servers.

So I tried the above and it works, but I'd still like to be able to
leave the shell out of this.  And what about those process IDs?

One last question.  If I do the above, does the OS consider those 3
servers my scripts children?  I know that comes with some
responsibility (I've been looking at some things about the SIGCHLD
signals). oh, and btw, this is Solaris I'm talking about here.

Thanks guys and gals,

--Errin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Run a process in the background

2004-09-22 Thread Wiggins d Anconia
 Hi Perlers,
 
 I know that questions like this get asked all the time, but I guess
 it's just my turn to ask 'em!
 
 I need to kick of some processes in my script.  However, the script
 needs to kick them all off at once and then stick around to do some
 other things.  I'm kinda new to Perl, but in my OS's shell, I'd do
 this (actually, I DO do this ... this Perl script will be replacing
 this shell script):

 #!/bin/sh
 nohup /path/to/process/one/bin/server.sh /dev/null 21 
 nohup /path/to/process/two/bin/server.sh /dev/null 21 
 nohup /path/to/process/three/bin/server.sh /dev/null 21 


Shell is considerably different than Perl when it comes to this stuff...
 
 I figure I can pass that string directly to system() in Perl, 
 
   system nohup /path/to/process/one/bin/server.sh /dev/null 21 ;
   system nohup /path/to/process/two/bin/server.sh /dev/null 21 ;
   system nohup /path/to/process/three/bin/server.sh /dev/null 21 ;

A good figure, though I would expect this to fail, since system blocks,
but maybe not because the shell should be returning control.

 
 but that invokes the shell, right?  Also, I'd like to capture the
 Process ID of those 3 servers.
 

Yes it does.

 So I tried the above and it works, but I'd still like to be able to
 leave the shell out of this.  And what about those process IDs?
 

In this case you should look at the fork/exec model instead. It allows
you to start a separate process without blocking the parent which you
can then use to do other things while the forked process is running. The
best place to start is with the IPC (InterProcess Communication) docs under,

perldoc perlipc
perldoc -f fork
perldoc -f exec
perldoc -f wait
perldoc -f waitpid

This will cover forking/execing, signals, etc.

 One last question.  If I do the above, does the OS consider those 3
 servers my scripts children?  I know that comes with some
 responsibility (I've been looking at some things about the SIGCHLD
 signals). oh, and btw, this is Solaris I'm talking about here.
 

Sort of, in the case of Csystem the function manages the stuff you are
talking about automatically itself.  In the lower level you will have to
manage it, but the docs listed above should provide enough info to get
you through that.

 Thanks guys and gals,
 
 --Errin
 

Per usual this is where I will jump in and suggest POE if you are doing
anything that is not trivial. It makes managing all of this type of
multi-tasking garbage simple.

http://poe.perl.org

HTH,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Run a process in the background

2004-09-22 Thread John W. Krahn
Errin Larsen wrote:
Hi Perlers,
Hello,
I know that questions like this get asked all the time, but I guess
it's just my turn to ask 'em!
I need to kick of some processes in my script.  However, the script
needs to kick them all off at once and then stick around to do some
other things.  I'm kinda new to Perl, but in my OS's shell, I'd do
this (actually, I DO do this ... this Perl script will be replacing
this shell script):
#!/bin/sh
nohup /path/to/process/one/bin/server.sh /dev/null 21 
nohup /path/to/process/two/bin/server.sh /dev/null 21 
nohup /path/to/process/three/bin/server.sh /dev/null 21 
I figure I can pass that string directly to system() in Perl, 

  system nohup /path/to/process/one/bin/server.sh /dev/null 21 ;
  system nohup /path/to/process/two/bin/server.sh /dev/null 21 ;
  system nohup /path/to/process/three/bin/server.sh /dev/null 21 ;
but that invokes the shell, right?  Also, I'd like to capture the
Process ID of those 3 servers.
So I tried the above and it works, but I'd still like to be able to
leave the shell out of this.  And what about those process IDs?
One last question.  If I do the above, does the OS consider those 3
servers my scripts children?  I know that comes with some
responsibility (I've been looking at some things about the SIGCHLD
signals). oh, and btw, this is Solaris I'm talking about here.
The perlipc man page has a lot of information on how to run a child process 
and how to capture/ignore signals like HUP.

perldoc perlipc
This might do what you want (UNTESTED!)
my @children;
for my $server ( /path/to/process/*/bin/server.sh ) {
local $SIG{ HUP } = 'IGNORE';
defined( my $pid = fork ) or die Cannot fork: $!;
unless ( $pid ) {  # in child
open STDOUT, '', '/dev/null' or die $!;
open STDERR, '', '/dev/null' or die $!;
exec $server or die Cannot exec $server: $!;
}
push @children, $pid;
}

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response