Board index » delphi » CRT and redirecting

CRT and redirecting

Another question:
I'm using Turbo Pascal 5.5, and I've noticed that if the CRT unit is
used in a program, command-line redirection can't be used. Is there any
way of getting around this, other than writing my own routines rather
than using CRT?

--
+---------------+---------------------------+
| Iain Jones    | xh0u9...@NOSPAM.liv.ac.uk |
|               | (Remove the NOSPAM.)      |
+---------------+---------------------------+

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:CRT and redirecting


Quote
Iain Jones wrote:

> I'm using Turbo Pascal 5.5, and I've noticed that if the CRT unit is
> used in a program, command-line redirection can't be used. Is there any
> way of getting around this, other than writing my own routines rather
> than using CRT?

Look for "AssignCRT" (not sure if it is available in TP 5.5)

Or
Assign(OutPort,'');   (not OutPut in this case!)
ReWrite(OutPort);
Writeln(OutPort,'anything');
So you can distinguish between the outputs directly to the CRT
(without (OutPort,...)  and redirectable writes.

And look for Assign(Input,'');  Reset(Input);
Also look for DirectVideo.

:-)
--
Franz Glaser, Glasau 3, A-4191 Vorderweissenbach Austria +43-7219-7035-0
Muehlviertler Elektronik Glaser.  Industrial control and instrumentation
http://members.eunet.at/meg-glaser/           mailto:meg-gla...@eunet.at
http://www.geocities.com/~franzglaser/ http://members.xoom.com/f_glaser/

Re:CRT and redirecting


In article <7uphoa$n6...@nnrp1.deja.com>,
Iain Jones  <i_p_jo...@my-deja.com> wrote:

Quote
>Another question:
>I'm using Turbo Pascal 5.5, and I've noticed that if the CRT unit is
>used in a program, command-line redirection can't be used. Is there any
>way of getting around this, other than writing my own routines rather
>than using CRT?

You an use the following functions to check if the input or output is
redirected:

Function OutputRedirected:Boolean;
var rg:registers;
Begin
 rg.ax:=$4400;
 rg.bx:=1;
 MsDos(rg);
 OutputRedirected:=(rg.dl and 128=0) or (rg.dl and 2 = 0);
End;

Function InputRedirected:Boolean;
var rg:registers;
Begin
 rg.ax:=$4400;
 rg.bx:=0;
 MsDos(rg);
 InputRedirected:=(rg.dl and 128=0) or (rg.dl and 1 = 0);
End;

(If you want to know what they do, check the Ralf Brown's interrupt list)

If the output is directed, you can then do Assign(output,'');
Rewrite(output). After that the output goes where the redirection tells.
This does nothing to the CRT specific procedures (gotoxy etc.). You must
avoid them when you use redirection.

If you use an ansi terminal then  you can write your own routines. For
example gotoxy can be implemented as:

procedure GotoXY(X,Y: word);
var m1,m2:string[3];
begin
  str(X,m1);
  str(Y,m2);
  Write(esc+'['+m2+';'+m1+'H');
end;

ClrScr is

procedure ClrScr;
Begin
 Write(esc+'[H'+esc+'[2J');
end;

There, however would produce garbage if redirected to a printer.

You should have been more specific (that applies to 99% of the questions
here). You should have told what kind of a program you are writing and
what is the redirection problem you are talking about.

Osmo

Re:CRT and redirecting


On Fri, 22 Oct 1999 11:28:11 GMT, Iain Jones <i_p_jo...@my-deja.com>
wrote:

Quote
> I'm using Turbo Pascal 5.5, and I've noticed that if the CRT unit is
> used in a program, command-line redirection can't be used. Is there any
> way of getting around this, other than writing my own routines rather
> than using CRT?

It's not clear what you want. If writing your own routines for fast
screen output _would_ solve your problem then you can solve it without
writing your own routines.

        uses crt;
        var
          screen:text;
        begin
          { reopen standard output for DOS (redirectable) }
          assign(ouput,'');rewrite(output);
          { open file 'screen' for CRT output }
          assignCrt(screen);rewrite(screen);

Now

        writeln('hello')

would go by redirection to the file you specified on the command line
and

        writeln(screen,'hello');

would go to the screen by CRT. But if you didn't redirect then the
first writeln would go the screen, too. I'm not sure if you want this.
If not then give more specific information, please.

Regards
Horst

Re:CRT and redirecting


Quote
Iain Jones <i_p_jo...@my-deja.com> wrote:
>Another question:
>I'm using Turbo Pascal 5.5, and I've noticed that if the CRT unit is
>used in a program, command-line redirection can't be used. Is there any
>way of getting around this, other than writing my own routines rather
>than using CRT?

You'll find the answer to this and other frequently (and not so
frequently) asked Turbo Pascal questions in Timo's FAQ
<ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip>

You have two choices.  One is to assign a separate file to the DOS
redirected i/o and leave the default INPUT and OUTPUT files assigned
to the CRT device.
   Example:  Assign(F, ''); Reset(F);   { for input }
             Assign(G, ''); Rewrite(G); { for output }

Read, write, and close "F" and "G" as you would any text file.

The other solution is to assign the default INPUT and OUTPUT files
to the redirected I/O and when finished, restore them to the CRT
device.
   Example:  Assign(INPUT, ''); Reset(INPUT);     { for input }
             Assign(OUTPUT, ''); Rewrite(OUTPUT); { for output }

All default i/o would now be read from or written to the redirected
DOS files.  When finished, close the files and restore them to the
CRT device.
   Example:   AssignCRT(INPUT); Reset(INPUT);     { keyboard input }
              AssignCRT(OUTPUT); Rewrite(OUTPUT); { video output }

A variation of the second method would be to assign a second set of
files to the CRT device.  This would allow you to write program
status or other selected output to the screen as well as monitor
keyboard input which would allow the user to interrupt the program
using Crtl+BREAK, or Crtl+C.

   ...red

Re:CRT and redirecting


Try this.
-------------------------------------------------------------------------------------------------

program redir;
uses crt;
var k,m,n:integer;
    c:char;
    f:text;
begin
  if(paramstr(1)='/r') then begin
    assign(input,'');reset(input);
    assign(output,'');rewrite(output);
  end;
  assigncrt(output);rewrite(output);
  textcolor(3);
  writeln('Press any key to continue');
  c:=readkey;
  for k:=1 to 10 do begin
    writeln('Enter two numbers');
    readln(m,n);
    writeln(m,' + ',n,' = ',m+n);
  end;
  delay(3000);
  clrscr;
  for k:=1 to 100 do begin
  gotoxy(random(80),random(25));
  write('H');
  end;
end.
--------------------------------------------------------------------------

In this example, you need the /R switch (or some switch) to let the
program know that redirection
is happening. This program will read pairs of numbers and add them
together. The assign statements
will allow you to redirect a file (say nums.txt) as the input file so
the command would appear as

redir/r <nums.txt

Then the assigncrt statement which appears after that would allow the
output to be in color on the screen.

The point that you have to remember is that you can switch CRT off and
redirection on with

    assign(input,'');reset(input); ==================> to allow
redirected input
    assign(output,'');rewrite(output); ==============> to allow
redirected output

and switch CRTon and redirection off with

    assigncrt(input,'');reset(input); ================> to dis-allow
redirected input
    assigncrt(output,'');rewrite(output); ============> to dis-allow
redirected outpu.

You can write your program to use any combination of the above four
commands by assigning
enough command-line switches to the various combinations.

--
Patrick D. Rockwell
mailto:prockw...@thegrid.net
mailto:HNHC...@prodigy.net
mailto:patri48...@aol.com

Other Threads