how to properly call an executable from C code?
I have an external executable program( eg. prog.exe) that I will like to call from within my main program consisting of C code.
prog.exe will do some work and prints the output to a temp.txt file for my main program to use for analysis later.
Currently I have a function like:
So far it is able to print the results to the text file. However there are issues which I need some advice.
//in command prompt it is executed as C:> prog.exe options
retv = system("prog.exe options");
if(retv != 0)
1. My main program that calls prog.exe is a GUI program.If I call it this way a command prompt window will pop-up promptly then closes,which I think not so nice to be like this. Therefore,is there another better way which I can do the same without having the command prompt window popping up and close?
2. I need to ensure also that prog.exe has finished writing to the text file before my main program reads the file.Will there be any issue using system()?
3. How can I properly check if prog.exe has been executed successfully or having errors,since it is an external executable program?
fyi,I am using windows xp and mingw.
Thanks in advanced.