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