go back to original dir as soon as possible
This commit is contained in:
parent
0effa71276
commit
6864b9525d
|
@ -112,8 +112,8 @@ def execute(cmd,
|
||||||
|
|
||||||
"""
|
"""
|
||||||
initialPath = os.getcwd()
|
initialPath = os.getcwd()
|
||||||
os.chdir(wd)
|
|
||||||
myEnv = os.environ if env is None else env
|
myEnv = os.environ if env is None else env
|
||||||
|
os.chdir(wd)
|
||||||
process = subprocess.Popen(shlex.split(cmd),
|
process = subprocess.Popen(shlex.split(cmd),
|
||||||
stdout = subprocess.PIPE,
|
stdout = subprocess.PIPE,
|
||||||
stderr = subprocess.PIPE,
|
stderr = subprocess.PIPE,
|
||||||
|
@ -121,9 +121,9 @@ def execute(cmd,
|
||||||
env = myEnv)
|
env = myEnv)
|
||||||
out,error = [i for i in (process.communicate() if streamIn is None
|
out,error = [i for i in (process.communicate() if streamIn is None
|
||||||
else process.communicate(streamIn.read().encode('utf-8')))]
|
else process.communicate(streamIn.read().encode('utf-8')))]
|
||||||
|
os.chdir(initialPath)
|
||||||
out = out.decode('utf-8').replace('\x08','')
|
out = out.decode('utf-8').replace('\x08','')
|
||||||
error = error.decode('utf-8').replace('\x08','')
|
error = error.decode('utf-8').replace('\x08','')
|
||||||
os.chdir(initialPath)
|
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
raise RuntimeError('{} failed with returncode {}'.format(cmd,process.returncode))
|
raise RuntimeError('{} failed with returncode {}'.format(cmd,process.returncode))
|
||||||
return out,error
|
return out,error
|
||||||
|
|
Loading…
Reference in New Issue