Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2004-08-11 10:19:13


On Wed, 11 Aug 2004 11:33:50 -0300, Maurício wrote
> Hi,
>
> After I discovered Boost, which has regex and filesystem
> libraries, I decided to use C++ for tasks that I usually do with
> Ruby (a Perl-like language), because I know C++ a lot better than
> other languages. However, there's a feature of those languages I
> miss: the ability to call external programs and get the output as a
> string. Does any of Boost libraries (or other free libraries you
> know) have this capability?

There isn't a boost library, but it would be a nice addition. Turns out the
'system' call is available on both windows and unix so you can do something
like this:
  
  #include <stdlib.h>

  std::string command = "...your command here..."
  std::string tmpfile_name("...your temporary file name here...");
  std::string cmd = command + "> " + tmpfile_name;
  system(cmd.c_str());
  std::ifstream output(tmpfile_name.c_str());

Of course this has many limits an issues. If you want something more formal
pstreams might work for you:

http://pstreams.sourceforge.net/

HTH,

Jeff


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net