English 中文(简体)
德尔菲的阅读方案
原标题:Read program STDIN in Delphi
  • 时间:2011-08-14 01:59:11
  •  标签:
  • delphi
  • stdin

I have the following batch script:

dir | myapp.exe

该方案有这一来源(更多或更少):

procedure TForm1.FormCreate(Sender: TObject);
var buff: String;
begin
  Read(buff);
  Memo1.Lines.Text:=buff;
end;

而电线中的产出是:

驱动C的体积没有标签。

我尝试:

  • putting the read part into a loop with eof as a condition - somehow causing an infinite loop
  • writing a loop to keep reading until strlen(buff) is 0 - it exits the second time for some reason
  • reading stuff ever 0.5 seconds (I was thinking about asynchronous writes to stdin), this failed as well

这样,在没有数据的情况下直接实施该方案,就产生了《EInputOutput(I/O Error)代码6。

最佳回答

技研组没有固定的排位、排位或固定的梯子。 你可以做这样的事情:

procedure TForm1.FormCreate(Sender: TObject);
var
  Buffer: array[0..1000] of Byte;
  StdIn: TStream;
  Count: Integer;
begin
  StdIn := THandleStream.Create(GetStdHandle(STD_INPUT_HANDLE));
  Count := StdIn.Read(Buffer, 1000);
  StdIn.Free;
  ShowMessageFmt( %d , [Count]);
end;

如果是,

dir *.pas | myapp.exe

你们看着一个信息箱,其编号和编号为0,如果是:

myapp.exe

页: 1 在这两种情况下,表格都将显示。

问题回答

采用代号为<代码>Read(buff)

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




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签