How should I run another program from within my C program? I need to be able to write data into STDIN of the launched program (and maybe read from it’s STDOUT)
I am not sure if this is a standard C function. I need the solution that should work under Linux.
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
in a terminal to read more about it.
EDIT
Whether
popenproduces unidirectional or bidirectional pipes depends on the implementation. In Linux and OpenBSD,popenproduces unidirectional pipes, which are read-only or write-only. On OS X, FreeBSD and NetBSDpopenproduces bidirectional pipes.