可能重複:
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