popen() is a way to communicate with subprocesses using a file-like interface. It originated in C, but has been ported to other languages (via extensions) such as Python.
FILE *popen(const char *command, const char *type)
popen()
(Process OPEN) is a method by which programs can start and communicate with other programs using a file-like interface. This funcion is not mandated by ANSI, but is specified by POSIX.
popen()
allows the programmer to avoid the internal workings of fork()
and pipe()
(this is how it is implemented on UNIX-like systems) by presenting a file object. This allows for the use of functions such as fprintf()
and fscanf()
, presenting a more orthogonal interface to the programmer (excepting closing the process - the programmer must use pclose()
to stop a subprocess).
This function has been ported to a number of programming languages, such as Python (os.popen
), Ruby (IO.popen
), Tcl (open |command
), etc.