Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sudo_options: string or list of strings that will be passed as options to sudo
"""
cmd = _process_sudo_cmd(cmd, sudo, sudo_options)
stdout = None
if capture:
stdout = subprocess.PIPE
# Use the parent stdout and stderr
process = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=stdout)
lines = []
found_match = False
for line in process.communicate():
if line:
line = decodeUtf8String(line)
lines.append(line)
if re.search(no_newline_regexp, line) and found_match:
if not quiet:
sys.stdout.write(line)
found_match = True
else:
if not quiet:
sys.stdout.write(line)
print(line.rstrip())
found_match = False
output = {"message": lines, "return_code": process.returncode}
return output
def write(self, stream, message):
'''write will write a message to a stream,
first checking the encoding
'''
stream.write(decodeUtf8String(message))
def println(self, output, quiet=False):
'''print will print the output, given that quiet is not True. This
function also serves to convert output in bytes to utf-8
Parameters
==========
output: the string to print
quiet: a runtime variable to over-ride the default.
'''
if not self.quiet and not quiet:
print(decodeUtf8String(output))