[fpc-pascal] Redirecting input to a child process

Anton Shepelev anton.txt at gmail.com
Mon May 9 13:04:55 CEST 2011


Ludo Brands:

> If you need these handles from the child process use:
> InHnd:=GetStdHandle(STD_INPUT_HANDLE);
> OutHnd:=GetStdHandle(STD_OUTPUT_HANDLE);
> ErrHnd:=GetStdHandle(STD_ERROR_HANDLE);

Thank you, that's what I need.

By the way, it does work in a simple single-process applica-
tion:

    Program Test;
    uses Windows;

    var
       hIn:       LongWord;
       buf:       ShortString;
       bytesRead: LongWord;
    begin
       hIn := GetStdHandle(STD_INPUT_HANDLE);
       while(true) do begin
          ReadFile(hIn, buf[1], 5, bytesRead, nil);
          buf[0] := Chr(bytesRead);
          write(buf);
       end;
    end.

It is interesting to note that even this  code  reads  input
only after Enter is pressed.

Anton



More information about the fpc-pascal mailing list