Book HomeJava and XSLTSearch this book

22.14. Win32::Process

This module provides access to extended Win32 process creation and management abilities. Process objects are created with the Create method (the constructor). Additional methods can be used on objects to kill, suspend, resume, and set the priorities of processes.

The Create constructor has the following syntax:

Win32::Process->Create($Proc, app, cmnd, hndls, opts, dir)

The arguments to Create are as follows:

$Proc
Name of the reference for the created process object.

app
Full pathname of the executable.

cmnd
Command line for executable.

hndls
Determines handle inheritance. A value of 1 turns on inheritance; a 0 value turns it off.

opts
Sets options to implement when the process is created. The available options for this argument are listed below.

dir
The working directory for the executable.

The process is created by passing the command line in cmnd to the executable named in app. For example, a process object for a text file running in Notepad is created like this:

use Win32::Process;
Win32::Process->Create($proc, 'C:\\windows\\Notepad.exe',
                       "Notepad perlnut.txt", 1, 
                       DETACHED_PROCESS, ".");

The process creation options given by the opts argument to Create are:

CREATE_DEFAULT_ERROR_MODE
Gives the process the default error mode.

CREATE_NEW_CONSOLE
Creates a new console for the process. Can't be used with DETACHED_PROCESS.

CREATE_NO_CONSOLE
Creates a new process, but without running the process in a new and visible window. That is, a new process will be created, but in the background.

CREATE_NEW_PROCESS_GROUP
Creates process as root of a new process group.

CREATE_SEPARATE_WOW_VDM
Runs process in its own Virtual DOS Machine (VDM). Only applicable to 16-bit applications.

CREATE_SUSPENDED
Starts process in a suspended state. The process can be started with the Resume method.

CREATE_UNICODE_ENVIRONMENT
Uses Unicode characters in the environment block of the new process.

DEBUG_PROCESS
Debugs the new process with the calling process.

DEBUG_ONLY_THIS_PROCESS
Doesn't debug the new process if calling process is being debugged.

DETACHED_PROCESS
Creates a process with no access to the console of the calling process.

22.14.1. Win32::Process Methods

The following methods are provided for objects of created by Win32::Process.

GetExitCode

$proc->GetExitCode($ref)

Gets the exit code of a process and saves it to $ref.

GetPriorityClass

$proc->GetPriorityClass($ref)

Gets the priority class of the process and stores it in $ref.

Kill

$proc->Kill(exitcode)

Kills the process with the given exitcode, which is returned by the process.

Resume

$proc->Resume

Resumes a suspended process. This method can also be used on processes created with the CREATE_SUSPENDED flag.

SetPriorityClass

$proc->SetPriorityClass($priority)

Sets the priority class of the object to $priority. The priority can be one of the following:

IDLE_PRIORITY_CLASS
A process whith threads that run only when the system is idle

NORMAL_PRIORITY_CLASS
A process with normal scheduling

HIGH_PRIORITY_CLASS
A process that performs time-critical tasks that must be executed immediately

REALTIME_PRIORITY_CLASS
The highest-priority process, even preempts operating-system threads

Suspend

$proc->Suspend

Suspends the process.

Wait

$proc->Wait(n)

Waits n milliseconds for the process to exit. If the process times out, the method returns false and sets $! to WAIT_FAILED. For no timeout, sets n to INFINITE.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.