Util Subprocess

class dffml.util.subprocess.Subprocess(value)[source]

An enumeration.

async dffml.util.subprocess.run_command(cmd, logger=None, **kwargs)[source]

Run a command using asyncio.create_subprocess_exec().

If logger is supplied, write stdout and stderr to logger debug.

kwargs are passed to asyncio.create_subprocess_exec(), except for stdout and stderr which are pipes used for logging.

Examples

>>> import sys
>>> import asyncio
>>> import logging
>>>
>>> import dffml
>>>
>>> logging.basicConfig(level=logging.DEBUG)
>>> logger = logging.getLogger("mylogger")
>>>
>>> asyncio.run(dffml.run_command([
...     sys.executable, "-c", "print('Hello World')"
... ], logger=logger))

You should see “Hello World” in the logging output

DEBUG:asyncio:Using selector: EpollSelector
DEBUG:mylogger:Running ['/usr/bin/python3.7', '-c', "print('Hello World')"], {'stdout': -1, 'stderr': -1}
DEBUG:mylogger:['/usr/bin/python3.7', '-c', "print('Hello World')"]: stdout.readline: Hello World
DEBUG:mylogger:['/usr/bin/python3.7', '-c', "print('Hello World')"]: stderr.readline: