简体   繁体   中英

Get a return value from C++ program to a Python script using subprocess

I am using subprocess.Popen() in a Python script to run an executable of C++ program. I need to return a value from the C++ program which can be used in the Python script.

I have lots of printf statements in the C++ program, so I can't use PIPE and get the output.

Can I return a single value which is received by the script?

Check the returncode attribute of the object returned by Popen .

Note that it is only filled if you have called poll() or wait() first on the Popen object.

This issue is solved. Basically python script subprocess can recieve exit code. cpp file can return that code from int main() which can be used as exit code of the prog in python script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM