<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body smarttemplateinserted="true" bgcolor="#FFFFFF" text="#000000">
<div id="smartTemplate4-template">Hi,<br>
<br>
<p> how would you handle large output and large stderr?<br>
</p>
<br>
When you read from one and it writes to the other, the read
blocks. Then it keeps writing to the other buffer, till that is
full, and then its write is blocked, and it is deadlocked.<br>
<br>
Probably check NumBytesAvailable before reading?<br>
<br>
Bye,<br>
Benito </div>
<br>
<p><br>
</p>
<br>
<div class="moz-cite-prefix">On 02/28/2017 05:28 PM, Michael Van
Canneyt wrote:<br>
</div>
<blockquote
cite="mid:alpine.DEB.2.20.1702281724350.27470@home.telenet.be"
type="cite">
<br>
<br>
On Tue, 28 Feb 2017, Graeme Geldenhuys wrote:
<br>
<br>
<blockquote type="cite">Hi,
<br>
<br>
Can anybody see if there is something wrong with the code shown
below.
<br>
The code is copied from one of my earlier projects where I call
the FPC
<br>
compiler and it worked just fine in that project.
<br>
<br>
In the work I'm doing now, I'm calling the Delphi Command Line
Compiler,
<br>
and made a few minor tweaks to the code, but this method never
seems to
<br>
return when Delphi command line compiler is called, and I don't
see any
<br>
output. If I call other utilities (eg: Git etc) then I do see
output and
<br>
it works as expected. It's just the Delphi Command Line Compiler
that
<br>
now seems to be giving troubles.
<br>
<br>
I would really appreciate it is anybody could spare a moment.
Many thanks.
<br>
<br>
I marked two areas with "// ???" where I am unsure if I'm doing
the
<br>
right thing.
<br>
</blockquote>
<br>
poWaitOnExit should not be needed, as this will cause Execute to
wait for process exit...
<br>
<br>
It seems likely that this will interfere with reading from output:
when the
<br>
output buffer is full, the executed process will block.
<br>
<br>
The rest seems fine.
<br>
<br>
Also:
<br>
It may be that Delphi somehow writes directly to the console
buffer, in that
<br>
case you will not catch any output. But then you should see the
output on
<br>
the screen (just not caught by your process)
<br>
<br>
Michael.
<br>
<br>
<br>
<br>
<br>
<br>
<blockquote type="cite">
<br>
<br>
==================================
<br>
function TBuildDelphiProject.RunTProcess(const Binary: string;
args:
<br>
TStrings): boolean;
<br>
const
<br>
BufSize = 1024;
<br>
var
<br>
p: TProcess;
<br>
Buf: string;
<br>
Count: integer;
<br>
i: integer;
<br>
LineStart: integer;
<br>
OutputLine: string;
<br>
begin
<br>
p := TProcess.Create(nil);
<br>
try
<br>
p.Executable := Binary;
<br>
// ??? Is poWaitOnExit needed here, it is called later down
the code
<br>
p.Options := [poUsePipes, poStdErrToOutPut, poWaitOnExit];
<br>
// p.CurrentDirectory := ExtractFilePath(p.Executable);
<br>
p.ShowWindow := swoShowNormal; // ??? Is this needed?
<br>
<br>
p.Parameters.Assign(args);
<br>
DoLog(etInfo,'Running command "%s" with arguments
<br>
"%s"',[p.Executable, p.Parameters.Text]);
<br>
p.Execute;
<br>
<br>
{ Now process the output }
<br>
OutputLine:='';
<br>
SetLength(Buf,BufSize);
<br>
repeat
<br>
if (p.Output<>nil) then
<br>
begin
<br>
Count:=p.Output.Read(Buf[1],Length(Buf));
<br>
end
<br>
else
<br>
Count:=0;
<br>
LineStart:=1;
<br>
i:=1;
<br>
while i<=Count do
<br>
begin
<br>
if Buf[i] in [#10,#13] then
<br>
begin
<br>
OutputLine:=OutputLine+Copy(Buf,LineStart,i-LineStart);
<br>
writeln(OutputLine);
<br>
OutputLine:='';
<br>
if (i<Count) and (Buf[i+1] in [#10,#13]) and
<br>
(Buf[i]<>Buf[i+1]) then
<br>
inc(i);
<br>
LineStart:=i+1;
<br>
end;
<br>
inc(i);
<br>
end;
<br>
OutputLine:=Copy(Buf,LineStart,Count-LineStart+1);
<br>
until Count=0;
<br>
if OutputLine <> '' then
<br>
writeln(OutputLine);
<br>
p.WaitOnExit;
<br>
Result := p.ExitStatus = 0;
<br>
if Not Result then
<br>
Writeln('Command ', p.Executable ,' failed with exit code:
',
<br>
p.ExitStatus);
<br>
finally
<br>
FreeAndNil(p);
<br>
end;
<br>
end;
<br>
==================================
<br>
<br>
<br>
Regards,
<br>
Graeme
<br>
<br>
-- <br>
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
<br>
<a class="moz-txt-link-freetext" href="http://fpgui.sourceforge.net/">http://fpgui.sourceforge.net/</a>
<br>
<br>
My public PGP key: <a class="moz-txt-link-freetext" href="http://tinyurl.com/graeme-pgp">http://tinyurl.com/graeme-pgp</a>
<br>
_______________________________________________
<br>
fpc-pascal maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<br>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>
<br>
<br>
</blockquote>
_______________________________________________
<br>
fpc-pascal maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<br>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>
<br>
</blockquote>
<br>
</body>
</html>