"""Clean up any resources managed by this object."""
pass
- def run(self, cmd, cwd=None, ignore_errors=False, stdin=None):
+ def run(self, cmd, cwd=None, ignore_errors=False, stdin=None, env=None):
"""Run a command as a sub-process, and log the results.
The output is available at self.output which can be useful if there is
or exits with an error code, otherwise an exception will be
raised if such problems occur.
stdin: Input string to pass to the command as stdin (or None)
+ env: Environment to use, or None to use the current one
Returns:
The output as a string.
try:
p = subprocess.Popen(cmd, cwd=cwd,
stdin=subprocess.PIPE if stdin else None,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
(stdout, stderr) = p.communicate(input=stdin)
if stdout is not None:
stdout = stdout.decode('utf-8')
return
raise Exception('File can still be opened')
-def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
+def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None, env=None):
"""Run a command and log its output.
Args:
an error code, otherwise an exception will be raised if such
problems occur.
stdin: Input string to pass to the command as stdin (or None)
+ env: Environment to use, or None to use the current one
Returns:
The output as a string.
if isinstance(cmd, str):
cmd = cmd.split()
runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
- output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin)
+ output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env)
runner.close()
return output