Newsgroups: comp.lang.pascal
Path: utzoo!utgpu!watserv1!maytag!watstat.waterloo.edu!dmurdoch
From: dmurdoch@watstat.waterloo.edu (Duncan Murdoch)
Subject: Re: About Emptying COM1 port
Message-ID: <1990Sep5.041231.28668@maytag.waterloo.edu>
Sender: daemon@maytag.waterloo.edu (Admin)
Organization: University of Waterloo
References: <34753@unix.cis.pitt.edu> <1990Sep5.010347.26099@nmt.edu>
Date: Wed, 5 Sep 90 04:12:31 GMT
Lines: 63

In article <1990Sep5.010347.26099@nmt.edu> jrwsnsr@nmt.edu (Jonathan R. Watts) writes:
>From article <34753@unix.cis.pitt.edu>, by cncst@unix.cis.pitt.edu (Christophe N. Christoff):
>> [...]
>> I used 
>> 
>> echo a | copy autoexec.bat com1
>> 
>> DOS simply ignore all this pipeline!!
>
>The reason DOS ignores the pipeline is because it always clears the
>keyboard buffer when it gives you that infamous error message...you can't
>type ahead.  If you happen to use 4DOS, you could say
>
>keystack 0 "a" ^ copy autoexec.bat com1
>
>but that is rather kludgy, and does you no good if you don't use 4DOS.

I think you can also make the pipe work by redirecting STDERR to STDOUT, because
DOS seems to be reading the key on STDERR.  I'm not sure, not having done it 
exactly, but when I ran a little program that redirected STDERR, then caused a 
critical error, it stopped dead when run alone and went merrily along when piped
an "a" as above.

Here's the program, in case anyone's interested in experimenting.

Duncan Murdoch
dmurdoch@watstat.waterloo.edu

{$M 4096,0,0}
uses
  dos;

const
  stderr = 2;

procedure force_dup(existing,second:word);
var
  r:registers;
begin
  r.ah := $46;
  r.bx := existing;
  r.cx := second;
  msdos(r);
  if (r.flags and fcarry) <> 0 then
    writeln('Error ',r.ax,' changing handle ',second);
end;

var
  stdfile : text;
begin
  assign(stdfile,'');
  reset(stdfile);

  { Redirect STDERR }

  force_dup(textrec(stdfile).handle,stderr);

  { Cause a critical error, because there's no disk there }

  swapvectors;
  exec(getenv('comspec'),'/c dir a:');
  swapvectors;
end.
