How to run a shell command but not waiting for the result ?

2003-07-14 Thread LI NGOK LAM
I've tried to use exec, system, and ``. And also with and without $| = 1;
but seems unable to do what I want.

What I want to do is suppose like this :

print Start;
exec notepad;
print End;

but I found my results are :

If I can see End, the notepad won't come,
If I can run the notepad, I can't see the End
until I close the notepad.

So what can I do to make it possible to run the notepad, 
but then just leave it alone and go on with the rest of the
code ?

TIA

Re: How to run a shell command but not waiting for the result ?

2003-07-14 Thread Beau E. Cox
- Original Message - 
From: LI NGOK LAM [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, July 14, 2003 6:05 AM
Subject: How to run a shell command but not waiting for the result ?


I've tried to use exec, system, and ``. And also with and without $| = 1;
but seems unable to do what I want.

What I want to do is suppose like this :

print Start;
exec notepad;
print End;

but I found my results are :

If I can see End, the notepad won't come,
If I can run the notepad, I can't see the End
until I close the notepad.

So what can I do to make it possible to run the notepad, 
but then just leave it alone and go on with the rest of the
code ?

TIA

Hi -

If you have Perl 5.8, try threads:

use strict;
use warnings;
use threads;

my $thr = threads-new(\notepad);
$thr-detach;

my $wait = 10;
while ($wait--) {
print still alive $wait\n;
sleep 1;
}
print ending\n;

sub notepad
{
system 'notepad';
}

see: perldoc perlthtut
(or as an html file under your html/lib/Pod
directory in your perl install tree.)

You first try won't work:

exec = NEVER returns (overlays you with
  notepad);
system = puts you into a wait till notepad finishes.

Aloha = Beau;
== please visit ==
http://beaucox.com = main site
http://howtos.beaucox.com = howtos
http://PPM.beaucox.com = perl PPMs
http://CPAN.beaucox.com = CPAN
== thank you ==



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to run a shell command but not waiting for the result ?

2003-07-14 Thread Jenda Krynicky
From: LI NGOK LAM [EMAIL PROTECTED]
 I've tried to use exec, system, and ``. And also with and without $| =
 1; but seems unable to do what I want.

If everything else fails, try to read the manual :-)

perldoc -f exec
  exec LIST
  exec PROGRAM LIST
The exec function executes a system command *and never
returns*-- use system instead of exec if you want it to
return. It fails and returns false only if the command does not
exist *and* it is executed directly instead of via your system's
command shell (see below).
...

So exec() is definitely not what you are after.

You want
system( 1, notepad);

perldoc perlport
system(1, @args)
spawns an external process and immediately returns its process
designator, without waiting for it to terminate.  Return value may
be used subsequently in Cwait or Cwaitpid.  Failure to spawn() 
a subprocess is indicated by setting $? to 255  8.  C$? is set
in a way compatible with Unix (i.e. the exitstatus of the subprocess
is obtained by $?  8, as described in the documentation).  

Actually this is something that should be documented better. It may 
seem that the system( 1, ...) only works on Win32 which is not true.

Anyway ... another option would be to use Win32::Process module.

HTH, Jenda

= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to run a shell command but not waiting for the result ?

2003-07-14 Thread Paul Johnson
On Mon, Jul 14, 2003 at 06:31:31PM +0200, Jenda Krynicky wrote:

 You want
   system( 1, notepad);

 Actually this is something that should be documented better.

I don't think anyone really wants to document it because it is such an
ugly hack :-(

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to run a shell command but not waiting for the result ?

2003-07-14 Thread Jenda Krynicky
From: Paul Johnson [EMAIL PROTECTED]
 On Mon, Jul 14, 2003 at 06:31:31PM +0200, Jenda Krynicky wrote:
 
  You want
  system( 1, notepad);
 
  Actually this is something that should be documented better.
 
 I don't think anyone really wants to document it because it is such an
 ugly hack :-(

Yeah it's pretty ugly. I think they should either create a new 
builtin function for this or add a hashref parameter that would 
contain options. I'm sure people could come up with all kinds of 
handy options.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]