By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

Dump program results to file

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
I guess my OS supported the command. Thanks, it works great.

Jul 9 '06 #3

P: n/a
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.