Ada Home
February 3, 1998

Article

A Thick Ada 95 Binding for
Unix Child Processes and Pipes

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 Unix Pipe Commands

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 Binding: Interface

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 Binding: Implementation

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.

Test Program

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.


Resources


What did you think of this article?

Very interesting
Interesting
Not interesting
Too long
Just right
Too short
Too detailed
Just right
Not detailed enough
Comments:

Page last modified: 1998-02-04