作者kkk5566 (kkk5566)
看板Python
標題[問題] os.system 執行一程式 取其 return 值
時間Wed Apr 14 16:45:18 2010
如果我執行一個程式 會 print 計算結果在 stdout 上
那麼我該如何在 python 中接到他的 return value 呢?
比方說 hello.pl 是一個會在 stdout 上 print hello 的一支小程式
os.system('hello.pl')
該如何接他的 return value?
很明顯不是
some_var = os.system('hello.pl')
就是了…
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.83.216.112
推 Sforever:import popen2; popen2.popen2("echo ss")[0].read() 04/14 18:10
→ suzuke:commands.getoutput("執行xxx") 09/28 15:53