Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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 garb1.pl 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\garb1.pl', 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.

Comment on two questions about Win32::Process
Download Code
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\garbl.pl'; exit 1; } sleep(2); kill(15,$pid);

    other resources: waitpid, wait, alarm...

    --
    Marco Antonio
    Rio-PM

      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\garb1.pl', 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://452700]
Approved by moot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-07-23 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls