我将尝试从一个使用子进程运行的C++程序中的一组打印语句中读取数据。
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()
然而我并没有得到数据,只得到了一个单独的整数,即退出码,要么是0,要么是错误码。当然,Python随后告诉我"AttributeError: 'int' object has no attribute 'communicate'"(属性错误:'int'对象没有属性'communicate')。
我该如何获取实际的数据(printf)?