468,456 Members | 1,702 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,456 developers. It's quick & easy.

Dump program results to file

I am writing a c++ program that will run multiple *.exe files and dump
the results to a file. In my test case, I am using netstat. I am
running netstat from my c++ program with the

system("netstat.exe");

command. I have already tried the following:
________________________
ofstream t;
t.open("tempp.txt");
t<<system("netstat.exe");
t.close();
________________________
The only response I am getting is that tempp.txt has a zero written in
the file. Does anyone have any ideas.

Thanks

Jul 9 '06 #1
3 2001
Reggie wrote:
I am writing a c++ program that will run multiple *.exe files and dump
the results to a file. In my test case, I am using netstat. I am
running netstat from my c++ program with the

system("netstat.exe");

command. I have already tried the following:
________________________
ofstream t;
t.open("tempp.txt");
t<<system("netstat.exe");
t.close();
________________________
The only response I am getting is that tempp.txt has a zero written in
the file. Does anyone have any ideas.
I think, the std::system( command ) call does not open a pipe to the process
running command interacting with streams. Thus, by itself, std::system()
cannot make the output of the command it runs available to the program. You
need to redirect the output of the command *within* the std::system() call.
Try something like

std::system( "netstat.exe tempp.txt" );

This has a chance of working if the OS supports pipes.

It would be nice though, if there was a function like

void std::system_bg ( char const * cmd,
std::istream & to_cmd, std::ostream & from_cmd )

in the library. It is quite possible that your platform has some support for
this using a function of another name. (That one, however, would be
off-topic in this group.)
Best

Kai-Uwe Bux
Jul 9 '06 #2
I guess my OS supported the command. Thanks, it works great.

Jul 9 '06 #3
Hi,
I think, popen could be used in this case. Basically, popen opens a
pipe to the process which can then be read like a normal file handle.

http://www.opengroup.org/pubs/online...xsh/popen.html

Thanks and regards
Sonison James
Reggie wrote:
I guess my OS supported the command. Thanks, it works great.
Jul 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Guenter Walser | last post: by
reply views Thread by Johnson, Shaunn | last post: by
7 posts views Thread by Matt | last post: by
7 posts views Thread by Cyril VELTER | last post: by
2 posts views Thread by Auddog | last post: by
14 posts views Thread by Sheldon | last post: by
1 post views Thread by TYR | last post: by
4 posts views Thread by Aidan | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.