可能重复:
Running shell command from python and capturing the output简单的python命令来捕获shell执行输出?
当我想捕捉shell执行输出,我这样做。
declare TAGNAME=`git describe --tags`
简单。我在Python中寻找这个,但其中大多数看起来非常复杂。什么是最简单的方法来做到这一点?是的,我知道我可以创建一个函数,但是我想知道预定义的函数是否存在。
tagname = theFunc('git describe --tags')
需要为返回的字符串调用'.strip('\ n')'。 – Eonil
@Eonil为什么要调用'.strip('\ n')'?拥有'\ n'真的很重要吗? – quantum
@xiaomao是的。因为我会将字符串传递给另一个shell命令。如果你意想不到的结果会很好,那真是太好了。 – Eonil