简体   繁体   中英

Is there a way to continuously collect output from a Python script I'm running into a c++ program?

So, I'm currently trying to construct a c++ aplication that calls for a python script. The main idea is that the python script runs a loop and prints decisions based on user input. I want the cpp program to be able to wait and read(if there s an output from python). I tried to make them "talk" via a file but it turned out bad. Any ideas?

PS: im calling the script using system("start powershell.exe C:\\python.exe C:\\help.py"); If there is any better way please let me know! Thanks

You could write to a file from python and check every certain amount of time in the c++ program to check for any changes in the file.

No, there is no standard way to capture the output if you start the program using std::system .

The operating system facility that you're looking for is "stream". The standard C++ provides access only to the standard streams, which you can use if you redirect the output of the python program when you start the C++ program. Example shell command:

python help.py > cpp_program

If you do this, then you can continuously read the output from the standard input stream in the C++ program. There is no standard way to create extra streams in C++, although that possibility is typically provided by the operating system.

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