在Delphi控制台应用程序中打开stdin / stdout上的TStream

时间:2021-06-19 00:06:08

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

我正在尝试编写一个Delphi控制台应用程序,为其标准输入创建一个TStream,为其标准输出创建另一个TStream。

(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.)

(它将由主机应用程序启动,其输入和输出重定向到管道,并将二进制数据传入/传出该主机应用程序,因此TStream将比ReadLn / WriteLn更适合于该任务。)

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

如何在标准输入或标准输出上打开TStream?

1 个解决方案

#1


Off the top of my head:

脱离我的头顶:

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

Give that a go..

放手吧......

#1


Off the top of my head:

脱离我的头顶:

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

Give that a go..

放手吧......