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

C

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!
 
N

Narthring

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;
}
 
X

xhoster

Cod said:
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
 
B

Ben Morrow

Quoth Cod said:
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
 
C

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:)
 
A

A. Sinan Unur

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
 
C

Cod

@l22g2000prc.googlegroups.com:











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 <[email protected]>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>- -

- -

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top