BACKGROUND
DOS provides for redirection of input/output. A program designed to accept input from the keyboard and output to the screen can be made to accept input from a file and/or output to another file. For example, the following program is written for std in to std out.
But if you invoke it thus:
fCopy < test.txt
the contents of the file test.txt will be copied to the screen. Likewise:
fCopy < intest.txt > outest.txt
will copy the contents of intest.txt to outest.txt, even creating outest.txt.
PROBLEM
Even though the above example behaves as described my experience has been that some programs I write will not work this way. The redirection gets ignored and the input is from the keyboard and the output is to the screen even though I try to use redirection. What gives? I can't seem to find any technique that determines whether redirection will work with a program or not.
DOS provides for redirection of input/output. A program designed to accept input from the keyboard and output to the screen can be made to accept input from a file and/or output to another file. For example, the following program is written for std in to std out.
Code:
Program fCopy (input,output) ;
Var
Ch : Char ;
begin
while not Eof do begin
Read (Ch) ;
Write (Ch)
end
end.
But if you invoke it thus:
fCopy < test.txt
the contents of the file test.txt will be copied to the screen. Likewise:
fCopy < intest.txt > outest.txt
will copy the contents of intest.txt to outest.txt, even creating outest.txt.
PROBLEM
Even though the above example behaves as described my experience has been that some programs I write will not work this way. The redirection gets ignored and the input is from the keyboard and the output is to the screen even though I try to use redirection. What gives? I can't seem to find any technique that determines whether redirection will work with a program or not.