Ada Home
Site Guide
Welcome Tour
Online RM95
Ada FAQs

Follow this link to learn more about DocAda
DocAda: The Ada 95 Hypertext Reference Works for Serious Programmers.

Ada Home Floors: Resources | Marketplace | Ammunition Dept. | Discovery Tour | Network

Ada Home
February 3, 1998


A Thick Ada 95 Binding for
Unix Child Processes and Pipes

by Jim Rogers, Team Ada member

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.


What did you think of this article?

Very interesting
Not interesting
Too long
Just right
Too short
Too detailed
Just right
Not detailed enough
Resources | Marketplace | Ammunition | Discovery | Network
About... | Ada Home | Site Guide | Welcome Tour | Tutorials
Book Reviews | RM95 | FAQs | References | Compilers | Tools | Bindings
Bookshop | Job Center | Consultants Index | Vendors
Copyright © by Kempe Software Capital Enterprises (KSCE). All Rights Reserved. Reproduction in whole or in part in any form or medium without express written permission of KSCE is strictly prohibited. Ada Home and Home of the Brave Ada Programmers are trademarks of KSCE. Back to the main entrance of the Ada Home
Ada Home
Improvement makes strait roads; but the crooked roads without improvement are roads of Genius. —William Blake

Page last modified: 1998-02-04