我正在尝试使用特定的绝对路径启动脚本
from subprocess import check_output如果我运行:
# myscript.py check_command=['pwd'] ret=check_output(check_command,shell=True) print(ret) path_set_command=['cd MYABSPATH'] ret=check_output(path_set_command,shell=True) ret=check_output(check_command,shell=True) print(ret)它打印两次myscript.py所在的文件夹。 因此,我明白每次调用check_output重新创建shell中的环境变量。
如何使用check_ouput设置命令的路径? 我试图让我的命令为
ret=check_output(['cd MYABSPATH; ./otherscript.py'] ,shell=True)但是,如果我将参数传递给我的otherscript.py (将它们作为额外项目附加到包含该命令的列表中),则它们无法正确转发。
那么如何用foo bar参数在MYABSPATH运行MYABSPATH ?
I am trying to start a script from a specific absolute path using
from subprocess import check_outputIf I run:
# myscript.py check_command=['pwd'] ret=check_output(check_command,shell=True) print(ret) path_set_command=['cd MYABSPATH'] ret=check_output(path_set_command,shell=True) ret=check_output(check_command,shell=True) print(ret)it prints two times the folder where myscript.py is located. Hence, I understand that the environment variables in the shell are recreated each call to check_output.
How to set the path of a command with check_ouput? I have tried to have my command as
ret=check_output(['cd MYABSPATH; ./otherscript.py'] ,shell=True)however, if I pass arguments to my otherscript.py (appending them as extra item to the list containing the command) they are not correctly forwarded.
So how do I run otherscript.py in MYABSPATH with foo bar arguments?
最满意答案
你可以使用cwd:
foo = check_output("pwd", cwd="/MYABSPATH", shell=True)You could use cwd:
foo = check_output("pwd", cwd="/MYABSPATH", shell=True)更多推荐
发布评论