Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

two questions about Win32::Process

by dannoura (Pilgrim)
on Apr 29, 2005 at 18:07 UTC ( #452700=perlquestion: print w/replies, xml ) Need Help??
dannoura has asked for the wisdom of the Perl Monks concerning the following question:

I want to use Win32::Process to create multiple processes for a LWP script. I can't figure out two things:

  • The code below doesn't work (i.e. the script which is supposed to generate a file doesn't do it).
  • How do I run a sub (for example one which fetches a web page) instead of another script.

use Win32::Process; use Win32; sub ErrorReport{ print Win32::FormatMessage( Win32::GetLastError() ); } Win32::Process::Create(my $ProcessObj, $^X, 'c:\perl\progs\', 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $ProcessObj->Wait(2000); my $pid=$ProcessObj->GetProcessID(); my $exitcode=0; Win32::Process::KillProcess($pid, $exitcode); print $exitcode;


Any comments about coding style are welcome.

Replies are listed 'Best First'.
Re: two questions about Win32::Process
by mda2 (Hermit) on Apr 29, 2005 at 23:15 UTC
    You really need to use Win32::Process ?

    This module is design for call external programs (not created with perl)... Try use Perl's language and resources to do it.

    See perlipc's Background-Process and fork references.

    Skel code:

    use strict; use warnings; my $pid = fork(); unless ( defined($pid) ) { die "fork failure! "; elsif ( $pid ) { # child $SIG{HUP} = sub { print "HUP signal\n"; }; sleep(5); #-->> if use an external script, and not a file with parameters #>>>> reguire 'c:\perl\progs\'; exit 1; } sleep(2); kill(15,$pid);

    other resources: waitpid, wait, alarm...

    Marco Antonio

      Thanks. Only problem is I can't use fork. I tried but it doesn't seem to work too well on Win32, a fact which I saw was discussed a lot on SoPW. Open and IPC seem like a possible solution.

Re: two questions about Win32::Process
by ZlR (Chaplain) on Apr 30, 2005 at 11:14 UTC
    Hello dannoura,

    One thing is that it should be the full command inside the process create, ie :

    Win32::Process::Create(my $ProcessObj, $^X, 'perl c:\perl\progs\', 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport();
    If you are under perl 5.8, it's worth also having a look at Win32::Job .

    zlr .

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://452700]
Approved by moot
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2017-12-11 21:53 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (313 votes). Check out past polls.