libModglue: a C++ library for handling co-processes

Kasper Peeters, kasper.peeters (at) aei.mpg.de

Overview

The libModglue library is a C++ library with classes for forking external processes and asynchronous reading from streams. It takes away the burden of all subtleties involving the Unix fork call. The asynchronous read facility enables one to read on multiple input streams at the same time, without loosing any of the standard C++ stream facilities.
There are also several small additional programs bundled with modglue, such as a program to add readline capability to any command line program. Moreover, the modglue library extends the idea of standard Unix pipes by providing a general framework for the creation of new processes with more than just the standard stdin/stdout/stderr pipes.

Simple example

#include <modglue/modglue.hh>

modglue::pipe foopipe("foo", modglue::pipe::input,  0);
modglue::pipe barpipe("bar", modglue::pipe::output, 1);

void print(const string& txt)
   {
   cout << "received " << txt << " on foo pipe" << endl;
   cout << "sending something on bar pipe" << endl;
   while(txt!="end") {
      string str;
      if(!foopipe.read(str,2))
         break;
      }
   barpipe.sender("thank you!");
   }

int main(int argc, char **argv) 
   {
   modglue::main mm(&argc, &argv);

   mm.add(pipe1);
   mm.add(pipe2);

   foopipe.receiver.connect(slot(print));
   
   mm.run();
   }

Download

For all download information please visit the download page of cadabra.

Utilities

Several small programs are bundled with modglue. They provide some additional functionality that was easy to implement with the library, or are generally useful for command-line driven programs.
ptywrap

Starts a program with stdin/stdout/stderr connected to a pseudo tty device, and map them to fd 0,1,2. This can be used to trick programs like ftp or sed into thinking that they are running interactively.
> ptywrap [unix executable]
is all you need to know.

prompt

The prompt utility wraps other programs such that their input has the well-known readline behaviour. In other words, you can use the cursor keys for editing, there is a history, and so on. Useful for programs like ftp that lack this functionality.



$Id: index.html,v 1.38 2007/03/08 16:57:25 peekas Exp $