Execute program from within a C program

You want to use popen. It gives you a unidirectional pipe with which you can access stdin and stdout of the program.

popen is standard on modern unix and unix-like OS, of which Linux is one 🙂

Type

man popen

in a terminal to read more about it.

EDIT

Whether popen produces unidirectional or bidirectional pipes depends on the implementation. In Linux and OpenBSD, popen produces unidirectional pipes, which are read-only or write-only. On OS X, FreeBSD and NetBSD popen produces bidirectional pipes.

Leave a Comment