From: "Chris Miller" <chrismil@ozemail.com.au>
Subject: Streams - copying stdin to stdout
Date: 1999/02/07
Date: 1999-02-07T00:00:00+00:00 [thread overview]
Message-ID: <79jgaj$cjn$1@reader1.reader.news.ozemail.net> (raw)
To test the operation of Streams I wrote the following sample
program that copies standard input to standard output :
with Text_IO;
with Ada.Text_IO.Text_Streams;
with Interfaces;
procedure params is
Stdin : Ada.Text_IO.Text_Streams.Stream_Access;
Stdout : Ada.Text_IO.Text_Streams.Stream_Access;
C : Interfaces.Unsigned_8;
begin
Stdin := Ada.Text_IO.Text_Streams.Stream (
File => Text_IO.Standard_Input);
Stdout := Ada.Text_IO.Text_Streams.Stream (
File => Text_IO.Standard_Output);
while not Text_IO.End_Of_File loop
Interfaces.Unsigned_8'Read(Stdin,C);
Interfaces.Unsigned_8'Write(Stdout,C);
-- Text_io.Put_Line("Value of Char read is " &
Integer'Image(Integer(C)));
end loop;
end params;
The compiler was the recently released Gnat 3.11p on Debian 2.0 Linux.
Using vi I created a file called "input" containing the single line "test".
The program was compiled with gnatmake and then run as
./params < input > output
The output from ls -l was
-rw-rw-r-- 1 chrismil chrismil 5 Feb 7 16:54 input
-rw-rw-r-- 1 chrismil chrismil 4 Feb 7 18:09 output
The problem is that the input file has 5 bytes, which are the characters
"test" plus the line feed added by vi, however the output file is only
4 bytes.
Printing out the characters with the Text_IO statement confirms that
only 4 bytes were processed.
Is this a bug or am I missing something ?.
How does one copy a file, viewed as an unstructered block of bytes, from
standard input to standard output.
Chris Miller
chrismil@ozemail.com.au
7-Feb-1999
next reply other threads:[~1999-02-07 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-02-07 0:00 Chris Miller [this message]
1999-02-09 0:00 ` Streams - copying stdin to stdout Stephen Leake
1999-02-10 0:00 ` David Brown
1999-02-10 0:00 ` rdt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox