I/O with command prompt.

Lets say I'm using a command such as system("ipconfig") on a windows machine, how might I go about taking the information given from using ipconfig and storing it in a text file? Is this even possible?
It isn't simple.

On Windows, you need to use CreateProcess() along with one of the CreatePipe() functions. Read more here:
http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx

On Linux/Unix, you can use popen()
http://linux.die.net/man/3/popen


A really simple way to avoid all that grief is to simply use system() with a redirection in the shell command:
1
2
3
4
5
6
7
8
9
10
// Execute the "ipconfig" process and save the results in "out.txt".
system( "ipconfig > ipf.txt" );

// Now open the file and read the results
ifstream ipf( "ipf.txt" );
...
ipf.close();

// Don't forget to delete the file now that you are done with it
remove( "ipf.txt" );

Hope this helps.
Topic archived. No new replies allowed.