Forum > General
Parsing STDERR / STDOUT
pcurtis:
I use the following code to create a process (in a thread)
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- MyShell := TProcess.Create(nil); with MyShell do begin Options := [poUsePipes]; ShowWindow := swoHIDE; Executable := 'D:\Lazarus\Shared\mpv.exe'; Options := Options + [poUsePipes]; Parameters.Add('--wid=' + inttostr(WID)); while not MyQuery.EOF do begin Parameters.Add(MyQuery['fnPARAMETER'] + MyQuery['fnVALUE']); MyQuery.Next; end; Parameters.Add(ClipFilename); Execute; end; while (MyShell.Running) or (MyShell.Stderr.NumBytesAvailable > 0) do begin while MyShell.Stderr.NumBytesAvailable > 0 do begin fPlayVideoStatus := ''; begin ReadCount := Min(512, MyShell.Stderr.NumBytesAvailable); //Read up to buffer, not more MyShell.Stderr.Read(CharBuffer, ReadCount); fPlayVideoStatus := fPlayVideoStatus + CharBuffer; end; fWhere := 1; Synchronize(@PlayVideoStatus); end; while MyShell.Output.NumBytesAvailable > 0 do begin fPlayVideoStatus := ''; begin ReadCount := Min(512, MyShell.Output.NumBytesAvailable); //Read up to buffer, not more MyShell.Output.Read(CharBuffer, ReadCount); fPlayVideoStatus := fPlayVideoStatus + CharBuffer; end; fWhere := 2; Synchronize(@PlayVideoStatus); end;
All works fine except parsing STDERR / STDOUT.
I would like to Synchronize(@PlayVideoStatus) STDERR / STDOUT line by line (the sync code is fine). The problem really lyes in reading STDERR / STDOUT and parsing it.
I know @tedson has UnTerminal-1.0 that I think will do the trick, but I don't know how to integrate it.
Can anyone help?
jamie:
What are you talking about, splitting lines when line endings appears and then generate a line of out as a string ?
pcurtis:
So for example STDERR is read in 512 byte blocks. I want to break this into CRLF terminated strings. Data is constantly appearing on STDERR
jamie:
Use string routines
MyDataString
When you start set it to '';
in the loop just treat the 512 buffer has array of char and add a 0 at the end of it each time to ensure the routines work..
MyDataString := MyDataString+Pchar(@My512Buffer)^;
empty the My512 for next read.
If Pos(#13, MyDataString) <> 0 Then
Finalstring := Copy(…….) etc...
you know the rest...
I can give you example code block later...
jamie:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var Form1: TForm1; MyBufferList:TstringList; //Create this at start somewhere., keep it alive implementation {$R *.lfm} { TForm1 }Function StrFromMyBuf(Var theBuf:Array of Char;Count:Integer):TStringList;Begin Result := MyBufferList; If Count = 0 Then exit; Result.SkipLastLineBreak :=True; Result.Text := Result.Text+Copy(Pchar(@Thebuf)^,0,Count-1); If Result.Count > 100 Then Result.Delete(0); //Keep list limited;end;
Something like that.
that should give you something to work with.
make sure you empty the buffer each time you call this..
Navigation
[0] Message Index
[#] Next page