[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

pclose Subroutine

Purpose

Closes a pipe to a process.

Library

Standard C Library (libc.a)

Syntax


#include <stdio.h>
int pclose ( Stream)
FILE *Stream;

Description

The pclose subroutine closes a pipe between the calling program and a shell command to be executed. Use the pclose subroutine to close any stream you opened with the popen subroutine. The pclose subroutine waits for the associated process to end, and then returns the exit status of the command.

Attention: If the original processes and the popen process are reading or writing a common file, neither the popen subroutine nor the pclose subroutine should use buffered I/O. If they do, the results are unpredictable.

Avoid problems with an output filter by flushing the buffer with the fflush subroutine.

Parameter

Stream Specifies the FILE pointer of an opened pipe.

Return Values

The pclose subroutine returns a value of -1 if the Stream parameter is not associated with a popen command or if the status of the child process could not be obtained. Otherwise, the value of the termination status of the command language interpreter is returned; this will be 127 if the command language interpreter cannot be executed.

Error Codes

If the application has called:

one of these calls caused the termination status to be unavailable to the pclose subroutine, a value of -1 is returned and the errno global variable is set to ECHILD.

Related Information

The fclose or fflush (fclose or fflush Subroutine) subroutine, fopen, freopen, or fdopen (fopen, fopen64, freopen, freopen64 or fdopen Subroutine) subroutine, pipe (pipe Subroutine) subroutine, popen (popen Subroutine) subroutine, wait, waitpid, or wait3 subroutine.

Files, Directories, and File Systems for Programmers in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

Input and Output Handling Programmer's Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]