flush output
This will ensure that the stderr and stdout are running synchroniously. The output in journalctl will now make more sense.
This commit is contained in:
parent
1e96c4e5ee
commit
7756236e1c
1 changed files with 8 additions and 0 deletions
|
|
@ -47,7 +47,11 @@ def run_command(command, env=None):
|
||||||
current_env = os.environ.copy()
|
current_env = os.environ.copy()
|
||||||
if env is not None:
|
if env is not None:
|
||||||
current_env.update(env)
|
current_env.update(env)
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stderr.flush()
|
||||||
process = subprocess.run(command, shell=True, env=current_env)
|
process = subprocess.run(command, shell=True, env=current_env)
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stderr.flush()
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
raise RuntimeError(f"Command '{command}' failed with return code {process.returncode}, environment is {env}")
|
raise RuntimeError(f"Command '{command}' failed with return code {process.returncode}, environment is {env}")
|
||||||
|
|
||||||
|
|
@ -55,8 +59,12 @@ def get_command(command, env=None, full_return=False):
|
||||||
current_env = os.environ.copy()
|
current_env = os.environ.copy()
|
||||||
if env is not None:
|
if env is not None:
|
||||||
current_env.update(env)
|
current_env.update(env)
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stderr.flush()
|
||||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=current_env)
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=current_env)
|
||||||
output, error = process.communicate()
|
output, error = process.communicate()
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stderr.flush()
|
||||||
return_code = process.poll()
|
return_code = process.poll()
|
||||||
if full_return:
|
if full_return:
|
||||||
return output.decode().strip(), error.decode().strip(), return_code
|
return output.decode().strip(), error.decode().strip(), return_code
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue