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)?