Home > Software engineering >  Is there a way to continuously collect output from a Python script I'm running into a c progr
Is there a way to continuously collect output from a Python script I'm running into a c progr

Time:12-01

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

CodePudding user response:

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.

CodePudding user response:

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.

  • Related