trying to cover this topic, i decided to use directly pipes in delphi to support unicode files (+paths) in my program.i am turning to you for help cause i have no more ideas what i can do wrong.the code i paste below input file 'a.flac' to encoder through pipe, and receive the results through another one. function seems to work, but weirdly stops receiving data after about 98% done. the piece i save on the disc matches with respondent reference WAV file, except it is only a 98% piece. notice: whole flac file IS passed to encoder as i can see in in task manager.

if ProcessOK then while (BytesToWrite>0)and(WasOKwrite)and(bytesWritten>0) do begin WasOKwrite:=WriteFile(StdInPipeWrite, FileBuffer, BytesToWrite, bytesWritten, nil); while WaitForSingleObject(PI.hProcess, 20)=WAIT_OBJECT_0 do Application.ProcessMessages; repeat if PeekNamedPipe(StdOutPipeRead,nil,0,nil,@BytesToRead,nil) and (BytesToRead>0) then//Peek must be or hangs//after ~98% it says '0' bytes left begin setlength(PipeBuffer,BytesToRead); WasOKread:=ReadFile(StdOutPipeRead, PipeBuffer[0], BytesToRead, bytesRead, nil); Written:=M.Write(PipeBuffer[0], bytesRead); end else Break; until not WasOKread or (BytesRead = 0);

//there is no error anyway { repeat if PeekNamedPipe(StdErrPipeRead,nil,0,nil,@BytesToRead,nil) and (BytesToRead>0) then WasOKread:=ReadFile(StdErrPipeRead, Buffer, BytesToRead, bytesRead, nil) else Break; until not WasOKread or (BytesRead = 0);}

in a simplier version of this function, where i only capture the output and pass input to encoder normally'flac.exe -d -c --totally-silent a.flac'my 'reading' code looks like this (the simplier only-reading version works fine !!!):

if ProcessOK then repeat if PeekNamedPipe(StdOutPipeRead,nil,0,nil,@BytesRead,nil) and (BytesRead>0) then begin WasOKread:=ReadFile(StdOutPipeRead, Buffer, 65536, BytesRead, nil); M.Write(Buffer, bytesRead); end else break; until not WasOKread or (BytesRead = 0);

file is NOT read. from all i know, this function with these parameters ONLY checks if something is waiting in a pipe, so teoretically it is even more proper. but this is just what i found trying to make working the 'full' version above.

i hope you are smarter than me and will tell me whats wrong...!

//edit:i noticed ~98% on two (all i tried, big~22MB and small~0,5MB one) FLAC files. when i tried same thing with lame and 52KB MP3 file, i got only 53KB output, instead of 517KB. i also noticed, that small changes in code, like now

CODE

while WaitForSingleObject(PI.hProcess, 20)=WAIT_OBJECT_0 do Application.ProcessMessages;

becomes->

CODE

while WaitForSingleObject(PI.hProcess, 10)=WAIT_OBJECT_0 do Application.ProcessMessages;

i got less output, so if before i got from 437KB FLAC file always 448KB output, now i have 432KB. but no matter how much time i give, its never more than that previous 448KB.