如何在Python中运行bash脚本,但就好像它从另一个目录运行?

如何在Python中运行bash脚本,但就好像它从另一个目录运行?,第1张

概述subprocess.call(['/home/blah/trunk/blah/run.sh', '/tmp/ad_xml', '/tmp/video_xml']) 我这样做但是,在我的run.sh中,我有“相对”路径.所以,我必须“cd”到该目录,然后运行shell脚本.我怎么做?最佳答案使用cwd参数subprocess.call()来自这里的文档:ht

subprocess.call(["/home/blah/trunk/blah/run.sh","/tmp/ad_xml","/tmp/vIDeo_xml"])

我这样做但是,在我的run.sh中,我有“相对”路径.
所以,我必须“cd”到该目录,然后运行shell脚本.我怎么做?最佳答案使用cwd参数subprocess.call()

来自这里的文档:http://docs.python.org/library/subprocess.html

If cwd is not None,the child’s
current directory will be changed to
cwd before it is executed. Note that
this directory is not consIDered when
searching the executable,so you can’t
specify the program’s path relative to
cwd.

例:

subprocess.call(["/home/blah/trunk/blah/run.sh","/tmp/vIDeo_xml"],cwd='/tmp')
总结

以上是内存溢出为你收集整理的如何在Python中运行bash脚本,但就好像它从另一个目录运行?全部内容,希望文章能够帮你解决如何在Python中运行bash脚本,但就好像它从另一个目录运行?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1047105.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存