API

Easy to use python subprocess interface.

class easyprocess.EasyProcess(cmd, ubuntu_package=None, url=None, cwd=None, use_temp_files=True)

simple interface for subprocess

shell is not supported (shell=False)

Warning

unicode is supported only for string list command (Python2.x) (check shlex for more information)

Parameters:
  • cmd – string (‘ls -l’) or list of strings ([‘ls’,’-l’])
  • cwd – working directory
  • use_temp_files – use temp files instead of pipes for stdout and stderr, pipes can cause deadlock in some cases (see unit tests)
call(timeout=None)

Run command with arguments. Wait for command to complete.

same as:
  1. start()
  2. wait()
  3. stop()
Return type:self
check(return_code=0)

Run command with arguments. Wait for command to complete. If the exit code was as expected and there is no exception then return, otherwise raise EasyProcessError.

Parameters:return_code – int, expected return code
Return type:self
check_installed()

Used for testing if program is installed.

Run command with arguments. Wait for command to complete. If OSError raised, then raise EasyProcessCheckInstalledError with information about program installation

Parameters:return_code – int, expected return code
Return type:self
is_alive()

poll process using subprocess.Popen.poll()

Return type:bool
pid

PID (subprocess.Popen.pid)

Return type:int
return_code

returncode (subprocess.Popen.returncode)

Return type:int
sendstop()

Kill process (subprocess.Popen.terminate()). Do not wait for command to complete.

Return type:self
sleep(sec)

sleeping (same as time.sleep())

Return type:self
start()

start command in background and does not wait for it

Return type:self
stop()

Kill process and wait for command to complete.

same as:
  1. sendstop()
  2. wait()
Return type:self
wait(timeout=None)

Wait for command to complete.

Timeout:
Return type:self
wrap(func, delay=0)
returns a function which:
  1. start process
  2. call func, save result
  3. stop process
  4. returns result

similar to with statement

Return type:
exception easyprocess.EasyProcessCheckInstalledError(easy_process)

This exception is raised when a process run by check() returns a non-zero exit status or OSError is raised.

exception easyprocess.EasyProcessError(easy_process, msg='')
easyprocess.Proc

alias of EasyProcess

easyprocess.extract_version(txt)

This function tries to extract the version from the help text of any program.

Previous topic

Usage

This Page