This is an appendix to Understanding Unix/Linux
Programming
written for people interested in Ada programming on POSIX
systems.
[...] listargs.adb, shows that the program does not even see the redirection notation on the command line.
% gnatmake listargs
[...]
% ./listargs testing one two
Number of arguments: 3
The arguments are:
name) './listargs'
1) 'testing'
2) 'one'
3) 'two'
This message is sent to standard error.
% ./listargs testing one two > xyz
This message is sent to standard error.
% cat xyz
Number of arguments: 3
The arguments are:
name) './listargs'
1) 'testing'
2) 'one'
3) 'two'
% ./listargs testing >xyz one two 2> oops
% cat xyz
Number of arguments: 3
The arguments are:
name) './listargs'
1) 'testing'
2) 'one'
3) 'two'
% cat oops
This message is sent to standard error.
%
The program stdinredir1.adb uses the Close-then-Open method.
% make stdinredir1 [...] % ./stdinredir1 line1 line1 testing line2 testing line2 line 3 here line 3 here root:x:0:0:root:/root:/bin/bash sashroot:x:0:0:sashroot:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh %
The program stdinredir2.adb uses the Open-Close-Duplicate-Close method.
The program stdinredir3.adb uses the Open-Duplicate_and_Close-Close method.
The program whotofile.adb demonstrates the method.
The program pipedemo.adb creates a pipe, and then uses it to send data to itself.
The program pipedemo2.adb shows how to
combine Create_Pipe and Fork to create a pair of
processes that communicate through a pipe.
The program pipe.adb combinex
Create_Pipe, Fork and Exec to run
two programs with a pipe from standard output of the first program to
standard input of the second program.
In pipe.adb, [...] By changing the test
elsif Process_ID > 0 then to elsif Process_ID = 0
then, the roles will be reversed. [...]
In pipe.adb, [...]
In pipe.adb, [...]
How is POSIX.IO.Duplicate like
POSIX.Files.Link?
Modify whotofile.adb, [...]
Write a program called sortfromfile.adb
,
[...]
Extend pipe.adb, [...]
POSIX.IO.Is_A_Terminal [...]. The library function
POSIX.IO.Is_A_Terminal uses the system call
POSIX.File_Status.Get_File_Status. [...]
Go to next chapter.
Understanding Unix/Linux Programming, Bruce Molay,
ISBN 0-13-008396-8.