How to continue process without waiting for the output of system()?

How to continue process without waiting for the output of system()?

am 30.08.2007 16:57:23 von Cod

For example , I wrote:

system("calc");
print "hello";

Before the calc program is closed, the print statement will not
excute.

Any way to change the behavior?
I have tried fork, and system("calc&"), all failed.

My OS is WinXP, and I use Active Perl 5.8.8.

Thanks for your help!

Re: How to continue process without waiting for the output of system()?

am 30.08.2007 17:45:45 von Narthring

On Aug 30, 9:57 am, Cod wrote:
> For example , I wrote:
>
> system("calc");
> print "hello";
>
> Before the calc program is closed, the print statement will not
> excute.
>
> Any way to change the behavior?
> I have tried fork, and system("calc&"), all failed.
>
> My OS is WinXP, and I use Active Perl 5.8.8.
>
> Thanks for your help!

If you want to use threads this will work:
use strict;
use warnings;
use threads;


my $thread = threads->create(sub { thread()});
print "hello\n";
$thread->join();

sub thread{
system("calc");
1;
}

Re: How to continue process without waiting for the output of system()?

am 30.08.2007 18:41:05 von xhoster

Cod wrote:
> For example , I wrote:
>
> system("calc");
> print "hello";

Without a newline in the print, you have to careful that buffering
isn't going to get you.

>
> Before the calc program is closed, the print statement will not
> excute.
>
> Any way to change the behavior?
> I have tried fork, and system("calc&"), all failed.

What do you mean by "failed"?

>
> My OS is WinXP, and I use Active Perl 5.8.8.


H:\>perl -e "fork or do {system('calc'); exit}; $|=1; print 'hello' "

Does what I expect.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB

Re: How to continue process without waiting for the output of system()?

am 30.08.2007 22:44:06 von Ben Morrow

Quoth Cod :
> For example , I wrote:
>
> system("calc");
> print "hello";
>
> Before the calc program is closed, the print statement will not
> excute.
>
> Any way to change the behavior?
> I have tried fork, and system("calc&"), all failed.

The (approximate) equivalent of 'cmd &' under NT is 'start cmd'. So

system "start calc";

As others have said, fork ought to work anyway.

Ben

Re: How to continue process without waiting for the output of system()?

am 31.08.2007 16:30:33 von Cod

Thank you all.

Use Narthring's method or xhos's method, there is one problem: BEFORE
the calc closed, the programe won't exit. Just like this:

d:\>perl -e "fork or do {system('calc'); exi
t}; $|=1; print 'hello' "
hello

AFTER calc closed, below appears:
d:\>

By Follow Ben Morrow say, I tried:
d:\>perl -e "fork or do {system('calc'); exi
t}; $|=1; print 'hello' "
hello
d:\>

This time it works just what I wanted.

Thank you all again, and sorry for my poor English:)

Re: How to continue process without waiting for the output of system()?

am 02.09.2007 02:59:37 von 1usa

Cod wrote in news:1188570633.227615.319150
@l22g2000prc.googlegroups.com:

> Thank you all.
>
> Use Narthring's method or xhos's method, there is one problem: BEFORE
> the calc closed, the programe won't exit. Just like this:
>
> d:\>perl -e "fork or do {system('calc'); exi
> t}; $|=1; print 'hello' "
> hello
>
> AFTER calc closed, below appears:
> d:\>
>
> By Follow Ben Morrow say, I tried:
> d:\>perl -e "fork or do {system('calc'); exi
> t}; $|=1; print 'hello' "
> hello
> d:\>
>
> This time it works just what I wanted.

If you want more control, you can use Win32::Process

#!/usr/bin/perl

use strict;
use warnings;

use FindBin qw( $Bin );

use Win32::Process;
use Win32;

sub ErrorMsg { Win32::FormatMessage( Win32::GetLastError() ) }

my $calc_path = q{C:/WINDOWS/system32/calc.exe};

my $calc_process;

Win32::Process::Create(
$calc_process,
$calc_path,
'calc',
0,
NORMAL_PRIORITY_CLASS,
$Bin
) or die sprintf "Error starting '%s': %s", $calc_path, ErrorMsg();

sleep 3;

$calc_process->Suspend();

sleep 3;

$calc_process->Resume();

sleep 10;

$calc_process->Kill(0);

__END__


Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines:

Re: How to continue process without waiting for the output of system()?

am 06.09.2007 18:12:25 von Cod

On 9 2 , 8 59 , "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> Cod wrote in news:1188570633.227615.319150
> @l22g2000prc.googlegroups.com:
>
>
>
>
>
> > Thank you all.
>
> > Use Narthring's method or xhos's method, there is one problem: BEFORE
> > the calc closed, the programe won't exit. Just like this:
>
> > d:\>perl -e "fork or do {system('calc'); exi
> > t}; $|=1; print 'hello' "
> > hello
>
> > AFTER calc closed, below appears:
> > d:\>
>
> > By Follow Ben Morrow say, I tried:
> > d:\>perl -e "fork or do {system('calc'); exi
> > t}; $|=1; print 'hello' "
> > hello
> > d:\>
>
> > This time it works just what I wanted.
>
> If you want more control, you can use Win32::Process
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use FindBin qw( $Bin );
>
> use Win32::Process;
> use Win32;
>
> sub ErrorMsg { Win32::FormatMessage( Win32::GetLastError() ) }
>
> my $calc_path = q{C:/WINDOWS/system32/calc.exe};
>
> my $calc_process;
>
> Win32::Process::Create(
> $calc_process,
> $calc_path,
> 'calc',
> 0,
> NORMAL_PRIORITY_CLASS,
> $Bin
> ) or die sprintf "Error starting '%s': %s", $calc_path, ErrorMsg();
>
> sleep 3;
>
> $calc_process->Suspend();
>
> sleep 3;
>
> $calc_process->Resume();
>
> sleep 10;
>
> $calc_process->Kill(0);
>
> __END__
>
> Sinan
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines: - -
>
> - -

thx, I've tried Win32::Process, It's very useful , although need more
typing:)