/usr/lib/python3/dist-packages/subuserlib/subprocessExtras.py is in subuser 0.6.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # -*- coding: utf-8 -*-
"""
Helper functions for running foreign executables.
"""
#external imports
import subprocess
import os
import tempfile
#internal imports
import subuserlib.test
def call(args,cwd=None):
"""
Same as subprocess.call except here you can specify the cwd.
Returns subprocess's exit code.
"""
process = subprocess.Popen(args,cwd=cwd)
(stdout,stderr) = process.communicate()
return process.returncode
def callBackground(args,cwd=None,suppressOutput=True,collectStdout=False,collectStderr=False):
"""
Same as subprocess.call except here you can specify the cwd.
Returns imediately with the subprocess
"""
stdout = None
stderr = None
if suppressOutput:
devnull = open(os.devnull,"a")
stdout = devnull
stderr = devnull
if collectStdout:
temp_stdout = tempfile.TemporaryFile(mode="r")
stdout = temp_stdout.fileno()
if collectStderr:
temp_stderr = tempfile.TemporaryFile(mode="r")
stderr = temp_stderr.fileno()
process = subprocess.Popen(args,cwd=cwd,stdout=stdout,stderr=stderr,close_fds=True)
if collectStdout:
process.stdout_file = temp_stdout
if collectStderr:
process.stderr_file = temp_stderr
return process
def callCollectOutput(args,cwd=None):
"""
Run the command and return a tuple with: (returncode,the output to stdout as a string,stderr as a string).
"""
process = subprocess.Popen(args,stdout=subprocess.PIPE,stderr=subprocess.PIPE,cwd=cwd)
(stdout,stderr) = process.communicate()
return (process.returncode,stdout.decode("utf-8"),stderr.decode("utf-8"))
|