Process wrapper for process execution and management.
The process wrapper provides the ability to start and stop an external
process, setting the process environment, working directory and state
i.e. a foreground process in which case a call to the start method will not return until the process has
exited, or a background process in which case the process is started in a
separate thread allowing concurrent execution within the testcase.
Processes started in the foreground can have a timeout associated with
them, such that should the timeout be exceeded, the process will be
terminated and control passed back to the caller of the method. The
wrapper additionally allows control over logging of the process stdout
and stderr to file, and writing to the process stdin.
Usage of the class is to first create an instance, setting all runtime
parameters of the process as data attributes to the class instance via
the constructor. The process can then be started and stopped via the start and stop methods of the class, as well as interrogated for
its executing status via the running method, and waited for its completion via the wait method. During process execution the
self.pid
and seld.exitStatus
data attributes
are set within the class instance, and these values can be accessed
directly via it's object reference.
|
__init__(self,
command,
arguments,
environs,
workingDir,
state,
timeout,
stdout=None,
stderr=None)
Create an instance of the process wrapper. |
source code
|
|
|
__stringToUnicode(self,
s)
Converts a unicode string or a utf-8 bit string into a unicode
string. |
source code
|
|
|
__writeStdin(self,
hStdin)
Private method to write to the process stdin pipe. |
source code
|
|
|
__quotePath(self,
input)
Private method to sanitise a windows path. |
source code
|
|
|
__startBackgroundProcess(self)
Private method to start a process running in the background. |
source code
|
|
|
__startForegroundProcess(self)
Private method to start a process running in the foreground. |
source code
|
|
|
__setExitStatus(self)
Private method to set the exit status of the process. |
source code
|
|
|
write(self,
data,
addNewLine=True)
Write data to the stdin of the process. |
source code
|
|
integer
|
running(self)
Check to see if a process is running, returning true if running. |
source code
|
|
|
|
|
|
|
|
|
start(self)
Start a process using the runtime parameters set at instantiation. |
source code
|
|