Dump program results to file

R

Reggie

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
 
K

Kai-Uwe Bux

Reggie said:
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::eek:stream & 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top