Re: Calling external program in C++
jcoffin_at_taeus.com
Date: 12/15/04
- Next message: David White: "Re: reading a declaration"
- Previous message: Mike Wahler: "Re: std::vector <mytype> allocation strategy"
- In reply to: Jon Slaughter: "Calling external program in C++"
- Next in thread: jcoffin_at_taeus.com: "Re: Calling external program in C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 14 Dec 2004 16:26:01 -0800
> is there a C++ method of calling an external executable program?
> I know you can do it using C, but what about C++?
Here's one possibility you might find interesting (this was a quick
hack at overhauling some code I wrote _years_ ago that used an
ostrstream, so it might benefit from some cleanup):
#include <sstream>
#include <cstdlib>
using std::ostringstream;
ostringstream &execute(ostringstream &s)
{
std::system(s.str().c_str());
return s;
}
ostringstream &operator<<(ostringstream &s,
ostringstream &(*manip)(ostringstream &s))
{
return manip(s);
}
int main() {
ostringstream x;
x << "ls " << execute;
return 0;
}
If you want to see the original code, it's at:
http://groups-beta.google.com/group/comp.lang.c++/msg/a2940ddf50edf667
I have to admit that until I looked at the date on that post, I hadn't
quite realized how old this really was. :-)
-- Later, Jerry. The universe is a figment of its own imagination.
- Next message: David White: "Re: reading a declaration"
- Previous message: Mike Wahler: "Re: std::vector <mytype> allocation strategy"
- In reply to: Jon Slaughter: "Calling external program in C++"
- Next in thread: jcoffin_at_taeus.com: "Re: Calling external program in C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|