September 23rd, 2003, 09:16 AM
Question about system()
Say I make a call like:
How do I get the output of the program I'm calling from the command line.
September 23rd, 2003, 10:08 AM
easiest way would be to send the output of the program to a file and then read the file.
system("c:\your_program.exe > results.txt");
then open and read results.txt
September 23rd, 2003, 10:14 AM
Cool thanks man, I'll do that.
I can specify the whole path, right?
Like c:\your_program.exe > c:\webdocs\results.txt
September 23rd, 2003, 10:18 AM
September 23rd, 2003, 11:09 AM
Be aware that a backslash also serves as an escape which allows you to insert special characters into a string, the most common one being the newline '\n'. In order for it to be read as a backslash, you need to enter two backslashes; eg: "c:\\your_program.exe > c:\\webdocs\\results.txt"
Another way to read the output of a command is through a pipe with popen(), which also replaces the system() call. popen will open a stream that you can handle and read almost exactly like a text file. As I recall, the only special things are opening it with popen and closing it with pclose.