Python subprocess with stdout redirect with int return

I am trying to read data from a set of print statements in a C ++ program that runs using a subprocess.

C ++ Code:

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 Code:

run = subprocess.call('Name', stdout = subprocess.PIPE, env={'LANG':'C++'})
data, error = run.communicate()

However, instead of getting the data, all I get is a single int, exit code, or 0, or an error code. Of course, python then tells me: "AttributeError: the int object does not have the communicate attribute.

How can I get data (printf)?

+5
source share
1 answer

subprocess.call ( python sys.exit(N) - In ). , subprocess.Popen. , :

run = subprocess.Popen('Name', stdout = subprocess.PIPE, env={'LANG':'C++'})
data, error = run.communicate()

returncode.

, :

run = subprocess.Popen('Name', stdout = subprocess.PIPE, stderr = subprocess.PIPE, env={'LANG':'C++'})
data, error = run.communicate()

run = subprocess.Popen('Name', stdout = subprocess.PIPE, env={'LANG':'C++'})
data, _ = run.communicate()

stderr, , , , - .

+4

All Articles