5
我想從正在使用子進程運行的C++程序中的一組打印語句中讀出數據。使用stdout重定向的Python子進程返回一個int
C++代碼:
printf "height= %.15f \\ntilt = %.15f \(%.15f\)\\ncen_volume= %.15f\\nr_volume= %.15f\\n", height, abs(sin(tilt*pi/180)*ring_OR), abs(tilt), c_vol, r_vol; e; //e acts like a print
Python代碼:
run = subprocess.call('Name', stdout = subprocess.PIPE, env={'LANG':'C++'})
data, error = run.communicate()
而不是獲取的數據。然而,所有我得到是單個int,退出代碼,可以是0或錯誤碼。當然,python會告訴我「AttributeError:'int'對象沒有'communic'屬性。
我該如何獲取數據(printf)?