[Back to REDIRECT SWAG index]  [Back to Main SWAG index]  [Original]

Here's a neat little ditty I converted from a C++ tip I saw in a mag a few
years ago.  It tests to see if its own output has been redirected and
returns a 1 if TRUE (redirected) or a 0 if FALSE (not redirected). This
function includes a sample prog that demonstrates its use. SIDE NOTE: I
put this function in the U_FILE.pas.tpu for use with all of my home-grown
file related functions and procedures.

TEST WITH: Test_Red (enter)
   [you should see a NOT REDIRECTED msg, 10 lines and a FINISHED msg.]

TEST WITH: Test_Red > this.dat (enter)
   [you should see a REDIRECTED msg, (no lines) and a FINISHED msg
    and the output of the lines will be in the this.dat file]

program test_red;

{$M 1024,0,655360}

** Function Name: fn_bRedirected()
** Description  : Determines if output has been redirected;
** Returns      : Integer to be treated as boolean;
** Calls        :
** Special considerations:
** Modification history:
** Created: 11/03/93 20:23

function fn_bRedirected : Integer; Assembler; {Treated as BOOLEAN}
  push  ds
  mov   ax,      prefixseg
  mov   ds,      ax
  xor   bx,      bx
  les   bx,      [bx + $34]
  mov   al,      es:[bx]
  mov   ah,      es:[bx +1]
  pop   ds
  cmp   al,      ah
  mov   ax,      1
  jne   @_exit
  xor   ax,      ax
  {mov   @Result, AX}

  Count    : Byte;
  hOutFile : text;

  Assign(hOutFile, 'CON');
  if not (boolean(fn_bRedirected)) then
    writeln(hOutFile, 'Not Redirected')
    writeln(hOutFile, 'Please wait while redirection is in progress');
  for Count := 1 to 10 do
    writeln('Line ', Count : 2);
  writeln(hOutFile, 'Finished!');

[Back to REDIRECT SWAG index]  [Back to Main SWAG index]  [Original]