30

I'm trying to write a Delphi console application that creates a TStream for its standard input, and another TStream for its standard output.

(It will be launched by a host app with its input and output redirected to pipes, and will be passing binary data to/from that host app, so TStream will be much better-suited to the task than ReadLn/WriteLn.)

How do I go about opening a TStream on standard input or standard output?

Joe White
  • 94,807
  • 60
  • 220
  • 330

1 Answers1

41

Off the top of my head:

  InputStream := THandleStream.Create(GetStdHandle(STD_INPUT_HANDLE));
  OutputStream := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));

Give that a go..

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
Allen Bauer
  • 16,657
  • 2
  • 56
  • 74