在MyCWD
(变量捕获工作目录)内运行的命令:
vagrant ssh -c "cd /Path/To/Dir && ./my-shell-script.sh -d argD -f argF"
我试过这样做,但没有成功:
vagrantCmd = ['vagrant','ssh','-c',
'cd', '/Path/To/Dir', '&&',
'./my-shell-script.sh', '-d', '-argD', '-f', 'argF']
output,error = subprocess.Popen(command, universal_newlines=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=MyCWD).communicate()
但是,如果我这样做,它只是工作:
argCmd = ['cd', '/Path/To/Dir', '&&',
'./my-shell-script.sh', '-d', '-argD', '-f', 'argF']
os.chdir(MyCWD)
os.system('vagrant ssh -c "%s"' % ' '.join(argCmd))
后者似乎容易得多,但不再推荐os.system
。我怎样才能让它与subprocess.Popen()
一起工作?你知道吗
我根据一些设置构建数组(argCmd
)。基本上,我构建了这样的数组,然后尝试将它们传递给subprocess.Popen
,但这种奇怪的字符串构建总是让我对该模块感到头痛,但对os.system
来说却相当琐碎。如何有效地使用字符串和subprocess
?你知道吗
我会尝试这样的方法:
以及:
请参见:
。。。基本上是逃跑的包装。也许是个装修工?或者像那样的花哨的东西。你知道吗
如何处理Python代码:
您需要:
如何修复?你知道吗
相关问题 更多 >
编程相关推荐