flowtool.execute

Functions for command execution.

Developed for python3, but it looks (?) as if they work just as good with python2.

class flowtool.execute.CompletedCommand(command, returncode, stdout, stderr)

Bases: tuple

command

Alias for field number 0

count(value) → integer -- return number of occurrences of value
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

returncode

Alias for field number 1

stderr

Alias for field number 3

stdout

Alias for field number 2

flowtool.execute.run_command(command, debug=None, **kwd)[source]

Wrapper for python3.4 subprocess.Popen, that waits for the command to finish and then gathers stdout, stderr as well as the returncode.

>>> run_command('true')
CompletedCommand(command=['true'], returncode=0, stdout='', stderr='')
>>> run_command(['false'])
CompletedCommand(command=['false'], returncode=1, stdout='', stderr='')
>>> run_command('ls /bin/ls')
CompletedCommand(command=['ls', '/bin/ls'], returncode=0, stdout='/bin/ls\n', stderr='')
>>> 'No such file or directory' in run_command(['ls', '_not_there_file_']).stderr
True
flowtool.execute.pformat_completed(result)[source]

Format a CompletedCommand for printing or logging.

>>> print(pformat_completed(run_command('true')))
==> Finished command: ['true']
Exit code: 0
stdout:

stderr:
flowtool.execute.main()[source]

Show some abilities of the execute module.

>>> main()
==> Finished command: ['ls', '-l']
Exit code: 0
stdout:
...