Ada Home
February 3, 1998
by Jim Rogers, Team Ada member
JimMaureenRogers@worldnet.att.net
This article presents a thick Ada 95 binding to the UNIX popen and pclose commands. These commands can be used to create a child process and obtain a pipe for reading or writing to that process.
Three files are provided: the specification and the implementation of the package Ada_Home.Unix.Pipe_Commands, and a test program.
The package Pipe_Commands defines the interface for a thick binding to the UNIX popen and pclose commands.
Popen initiates a child process and opens a pipe to that process. The pipe opened will either be opened with a read or a write mode. When opened for a write mode the utility allows the developer to write to the standard input of the child process. When opened for read mode the utility allows the developer to read the standard output of the child process.
Pclose closes the file stream associated with the pipe created by popen.
The first file, ada_home-unix-pipe_commands.ads, contains the package specification Pipe_Commands. The thick binding offers four subprograms: two functions, execute and read_next, and two procedures, close and write_next.
The second file, ada_home-unix-pipe_commands.adb, contains the package body, with the interface for functions "popen" and "pclose" (a thin binding to C functions), which are used in the implementations of the four subprograms declared in the package specification.
Finally, the third file, pipe_commands_test.adb, contains an example program of how this binding can be used. The program also demonstrates the use of the exceptions defined in the package specification.
URL http://www.adahome.com/articles/1998-02/code/
See also:
Page last modified: 1998-02-04