go back to original dir as soon as possible

This commit is contained in:
Martin Diehl 2020-04-26 14:52:27 +02:00
parent 0effa71276
commit 6864b9525d
1 changed files with 2 additions and 2 deletions

View File

@ -112,8 +112,8 @@ def execute(cmd,
"""
initialPath = os.getcwd()
os.chdir(wd)
myEnv = os.environ if env is None else env
os.chdir(wd)
process = subprocess.Popen(shlex.split(cmd),
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
@ -121,9 +121,9 @@ def execute(cmd,
env = myEnv)
out,error = [i for i in (process.communicate() if streamIn is None
else process.communicate(streamIn.read().encode('utf-8')))]
os.chdir(initialPath)
out = out.decode('utf-8').replace('\x08','')
error = error.decode('utf-8').replace('\x08','')
os.chdir(initialPath)
if process.returncode != 0:
raise RuntimeError('{} failed with returncode {}'.format(cmd,process.returncode))
return out,error