Execute a command with arguments and wait for output. Arguments should not be quoted!
Keyword arguments:
Parameters: |
---|
Example:
>>> code = 'import sys;sys.stdout.write('out');sys.exit(0)'
>>> status, out, err = execute('python', '-c', code)
>>> print('status: %s, output: %s, error: %s' % (status, out, err))
status: 0, output: out, error:
>>> code = 'import sys;sys.stderr.write('out');sys.exit(1)'
>>> status, out, err = execute('python', '-c', code)
>>> print('status: %s, output: %s, error: %s' % (status, out, err))
status: 1, output: , error: err
Executes a command with arguments and wait for output. If execution was successful function will return True, if not, it will log the output using standard logging and return False.
Retrieves a list of processes sorted by name.
Parameters: | |
---|---|
Return type: | list[(int, str)] or list[(int, str, str)] |
Returns: | List of process id, process name and optional cmdline tuples |
Find process by name or by argument in command line if arg param is available.
Parameters: | |
---|---|
Return type: | (int, str) |
Returns: | A tuple of process id, process name |
Kills a process by it’s process ID.
Parameters: | pid (int) – Process ID of the process to kill. |
---|
Abstract base class for the Process class that is implemented for every platform in it’s own module.
Simple example of Process class usage can be:
>>> from tea.process import Process
>>> p = Process('python', ['-c', 'import time;time.sleep(5);print 3'])
>>> p.start()
>>> p.is_running
True
>>> p.wait()
True
>>> p.read()
'3\n'
>>> p.eread()
''
Creates the Process object providing the command and it’s command line arguments.
The only required parameter is the command to execute. It’s important to note that the constructor only initializes the class, it doesn’t executes the process. To actually execute the process you have to call :met:`start`.
Parameters: |
|
---|
Read from the process standard error.
Return type: | str |
---|---|
Returns: | The data process has written to the standard error if it has written anything. If it hasn’t or you already read all the data process wrote, it will return an empty string. |
Property that returns the exit code if the process has finished running.
Return type: | int or None |
---|---|
Returns: | Exit code or None if the process is still running |
Property that indicates if the process is still running.
Return type: | bool |
---|---|
Returns: | True if the process is still running False otherwise |
Kills the process if it’s running.
Property that returns the PID of the process if it is running.
Return type: | int |
---|---|
Returns: | process id of the running process |
Read from the process standard output.
Return type: | str |
---|---|
Returns: | The data process has written to the standard output if it has written anything. If it hasn’t or you already read all the data process wrote, it will return an empty string. |
Starts the process.
Waits for the process to finish.
It will wait for the process to finish running. If the timeout is provided, the function will wait only timeout amount of seconds and then return to it’s caller.
Parameters: | timeout (None or int) – None if you want to wait to wait until the process actually finishes, otherwise it will wait just the timeout number of seconds. |
---|---|
Return type: | bool |
Returns: | Return value only makes sense if you provided the timeout parameter. It will indicate if the process actually finished in the amount of time specified, i.e. if the we specify 3 seconds and the process actually stopped after 3 seconds it will return True otherwise it will return False. |