mr-edd.co.uk :: horsing around with the C++ programming language

Introducing pexl: a process execution library

[9th August 2008]

I have just finished and uploaded the first version of pexl, a C++ library for easily executing processes and interacting with them using standard C++ streams and functors. Currently only UNIX is supported, though I plan to make the code work on Windows once I have access to a Windows machine at home again.

Here's a quick peek at how it can be used. For further information and download links, head over to the project page.

#include <pexl/exec.hpp>

// Run "find / -name *.h" to find all headers on the file system
// stdout output is forwarded to a stringstream.
// Any errors written to stderr are forwarded to std::cerr
// The process' stdin is fed from the contents of a file

std::ifstream input("somefile.txt");
std::ostringstream output;

const char *args[] = { "find", "/", "-name", "*.h" };

// Run from the current working directory, "."
int r = pexl::exec(args, args + 4, ".", pexl::in = input, pexl::out = output, pexl::err = std::cerr);

std::cout << "process returned: " << r << std::endl;

If you don't care about errors or input, say, you can simply omit them. pexl's named argument system allows you to specify only the streams you're interested in interacting with and in any order.

int r = pexl::exec(args, args + 4, ".", pexl::out = output);

I hope you find the library useful. There are still features to add (a Windows port, most importantly), but it's ready for use on UNIX.

Comments

(optional)
(optional)
(required, hint)

Links can be added like [this one -> http://www.mr-edd.co.uk], to my homepage.
Phrases and blocks of code can be enclosed in {{{triple braces}}}.
Any HTML markup will be escaped.