I want to read the std output of a system call into a C/C++ string. Can I do this without using a temp file?
Perl
//without file io
$output = `echo hello`;
C++
//with file io
system ("echo hello > tmp");
std::fstream file ("tmp");
std::string s;
file >> s;
This might help you redirect stdout from a system call.
Using C's
popen
(probably the simplest solution, even if it doesn't use C++'siostream
):Assuming your
iostream
has the non-standard xfstream::
xfstream(int fd)
constructor:Using Boost.Iostreams, you don't have to depend upon non-standard extensions to
iostream
:Unfortunately, Windows is horrible and
_popen
only works for console applications; for a graphical app:(completely untested)