Win32::Process
The most flexible way of starting a process on
Windows NT is to use the
Win32::Process
module.[88] Using this module,
you can select whether or not you want to wait for the child process
to run to completion, configure priorities, and suspend or resume
processes.
Even though we haven’t covered all of the relevant concepts, we
are going to run through a Win32::Process
example.
As shown, theWin32::Process
module contains a
method (subroutine) called Create
that does all
the work of creating a process:
use Win32::Process; Win32::Process::Create($Process, "c:\\nt\\system32\\notepad.exe", "notepad", 0, DETACHED_PROCESS, ".") || die "Create: $!";
This code creates an asychronous instance of
Notepad. Let’s take a look at the
parameters. The first parameter $Process
is a
scalar reference that receives the process object if the call
succeeds. We’ll discuss references in Chapter 18, but for now, you can just think of it as a
parameter that receives output.
The second argument is a fully qualified (system-dependent) path to the executable. The third argument is the command line passed to the program. In this case, we’re just invoking Notepad without any documents or options. The next argument specifies whether or not the new process inherits handles from the parent process (the Perl program). A value of one indicates that the process inherits any inheritable open handle in the parent process. Inheritable handles include I/O handles, socket handles, synchronization handles, and ...
Get Learning Perl on Win32 Systems now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.