Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to continue process without waiting for the output of system()?

Reply
Thread Tools

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

 
 
Cod
Guest
Posts: n/a
 
      08-30-2007
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!

 
Reply With Quote
 
 
 
 
Narthring
Guest
Posts: n/a
 
      08-30-2007
On Aug 30, 9:57 am, Cod <(E-Mail Removed)> 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;
}

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      08-30-2007
Cod <(E-Mail Removed)> 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
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      08-30-2007

Quoth Cod <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
Cod
Guest
Posts: n/a
 
      08-31-2007
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

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      09-02-2007
Cod <(E-Mail Removed)> 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:rocess

#!/usr/bin/perl

use strict;
use warnings;

use FindBin qw( $Bin );

use Win32:rocess;
use Win32;

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

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

my $calc_process;

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

 
Reply With Quote
 
Cod
Guest
Posts: n/a
 
      09-06-2007
On 9 2 , 8 59 , "A. Sinan Unur" <(E-Mail Removed)> wrote:
> Cod <(E-Mail Removed)> 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:rocess
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use FindBin qw( $Bin );
>
> use Win32:rocess;
> use Win32;
>
> sub ErrorMsg { Win32::FormatMessage( Win32::GetLastError() ) }
>
> my $calc_path = q{C:/WINDOWS/system32/calc.exe};
>
> my $calc_process;
>
> Win32:rocess::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 <(E-Mail Removed)>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>- -
>
> - -


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

 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ 8.35 How do I close a process's filehandle without waiting for it to complete? PerlFAQ Server Perl Misc 0 04-23-2011 04:00 AM
Capturing stdout without waiting for the process end Luigi Python 5 04-03-2006 07:24 PM
Waiting for a file deletion to continue =?Utf-8?B?RGlnZ2xlcg==?= ASP .Net 7 10-14-2004 11:05 AM
fork, childs, zombies, start a process in the background without waiting for it Rex Gustavus Adolphus Perl Misc 5 07-04-2003 10:12 AM



Advertisments