网上找的好多使用管道例子都不能算是实时的。必须等到控制台程序执行完毕后将管道内容输出至Memo中。我是使用THandleStream方式。但是如果控制台程序执行时间较长,而中间可能会不定期产生输出的话,那就不适合了。必须等长时间执行完毕后才能返回输出结果。有没有办法可以在控制台程序执行过程中实时输出内容?我本想将进程执行信息结构TStartupInfo的hStdOutput赋值直接给和memo显示有关的handle。但找不到这样的handle,而且如此的话也就不需要管道了。这个思路似乎不行。不知有无其他清晰及简单一点的办法。项目用在一个比较紧急但很小型的测试程序上。谢谢。
我的是Delphi 7。昨天才装的。
DosCommand1.OutputLines := Memo1.Lines;
DosCommand1.Execute;还需要设定什么吗?看它的说明和例子好像没其他的了呀。
the ouput in order to put it in a memo or in a listbox, ...
you can also send inputs.
the cool thing of this component is that you do not need to wait the end of
the program to get back the output. it comes line by line.我想应该还是我的问题吧。但是看来看去就那么几个属性。不用设了呀。
DosCommand1.OutputLines := Memo1.Lines; 注掉然后在onnewline事件里加上
memo1.Lines.Add(NewLine);
。。还是老样子,要等到程序执行完毕才反馈结果 :(
OnNewLine = DOScmdNewLine
OnTerminated = DOScmdTerminated
InputToOutput = False
MaxTimeAfterBeginning = 0
MaxTimeAfterLastOutput = 0
Left = 308
Top = 116
end
那DOScmdNewLine和DOScmdTerminated这两个函数是怎么填的?
DosCommand1.OutputLines没设?
谢谢
我问一下,如果在cmd中,打入dir c:\
会显示c盘下面的一些文件夹和文件
所显示的哪些文件夹和文件会不会在memo1中?
相当于dir c:\>>c:\1.txt
中txt中的内容一样?
对
可能连错误信息(stderr)也会有
begin
bdosstop:=true;
end;
procedure TFormMain.DOScmdNewLine(Sender: TObject; NewLine: String;
OutputType: TOutputType);
begin
FormMain.Mlog.Lines.Add('DOS|'+formatdatetime('hh:nn:ss.zzz',now)+':'+newline);
end;没设
http://2ccc.com/article.asp?articleid=2029
这是网址,楼主如果不嫌哪个exe的话,倒可以试试
就是flush的问题。不用在事件里写,设定DosCommand1.OutputLines就成