[Lazarus] TProcess, UTF8, Windows
Marcos Douglas
md at delfire.net
Fri Apr 13 15:42:38 CEST 2012
On Thu, Apr 12, 2012 at 5:30 PM, Marcos Douglas <md at delfire.net> wrote:
>
> On Thu, Apr 12, 2012 at 5:20 PM, Mattias Gaertner
> <nc-gaertnma at netcologne.de> wrote:
> > On Thu, 12 Apr 2012 12:34:59 -0300
> > Marcos Douglas <md at delfire.net> wrote:
> >
> >> Hi,
> >>
> >> I'm using the example in FreePascal wiki to execute external programs:
> >>
> >> http://wiki.freepascal.org/Executing_External_Programs#Reading_large_output
> >>
> >> I adapted this code to work in LCL, using a simple TMemo.
> >> All "write" and "writeln" was replaced with
> >> Memo1.Lines.Append(ConsoleToUTF8(<text or variable>)).
> >
> > What is the source of <text or variable>?
> > The output of the other process?
>
> I mean Write('.') or WriteLn(OutputLines[NumBytes]) etc.
> See the original code in the wiki.
>
> >> Everything works fine... but since I changed this line:
> >> OurProcess.Options := [poUsePipes];
> >> to
> >> OurProcess.Options := [poUsePipes, poNoConsole];
> >>
> >> ...the conversion ConsoleToUTF8 do not work.
> >>
> >> Any tips?
> >
> > Maybe the other process's output is not in console codepage.
> > Try
> >
> > Memo1.Lines.Append(<text or variable>)
> > or
> > Memo1.Lines.Append(SysToUTF8(<text or variable>)).
>
> I will try... but I see other problem now. The example read all buffer
> before print on screen (in my case, a TMemo).
> I want to print on time. I will change the code for this before try
> UTF8 conversion.
>
> Do you have an example for I need?
I resolved using:
procedure TConsoleTask.ReadingOutput;
var
NoMoreOutput: Boolean;
Buffer: string;
BytesAvailable: DWord;
BytesRead: LongInt;
begin
while FProcess.Running do
begin
BytesRead := 0;
BytesAvailable := FProcess.Output.NumBytesAvailable;
if BytesAvailable > 0 then
begin
SetLength(Buffer, BytesAvailable);
BytesRead := FProcess.OutPut.Read(Buffer[1], BytesAvailable);
DoLog(Copy(Buffer, 1, BytesRead)); //<<<< here fires an event
BytesAvailable := FProcess.Output.NumBytesAvailable;
end
else
Sleep(100);
end;
end;
IMHO, this could be present in TProcess, don't?
Or this is TAsyncProcess class serves?
Marcos Douglas
More information about the Lazarus
mailing list