Pascal StdIn/StdOut pipes -
i'm trying write pascal (lazarus/fpc) program started program process. caller (the arena chess gui) talks program using stdin , stdout.
first used readln in program text commands sent gui , writeln reply them. worked except program stop doing if readln had wait input gui. since wanted program carry on working , deal commands arrived had change this.
so changed code use:
... var inpstream : tinputpipestream; ... inpstream := tinputpipestream.create(stdinputhandle); ... if inpstream.numbytesavailable > 0 begin setlength(s_buffer, inpstream.numbytesavailable); inpstream.read(s_buffer[1], length(s_buffer)); end; ... that worked no longer paused read. writeln stopped working: nothing gets sent gui. thought maybe help:
... var inpstream : tinputpipestream; outstream : toutputpipestream; ... inpstream := tinputpipestream.create(stdinputhandle); outstream := toutputpipestream.create(stdoutputhandle); ... if inpstream.numbytesavailable > 0 begin setlength(s_buffer, inpstream.numbytesavailable); inpstream.read(s_buffer[1], length(s_buffer)); end; ... outstream.write(s_buffer, length(s_buffer)); but makes worse doesn't read or write anything. how can have non-blocked input on stdin while maintaining ability write stdout?
assuming use windows, means program reads output doesn't read enough (it lets mass up), , when total size of pipes reaches size (typically several mbs) windows stops processing.
this new situation require digging deeping windows pipes , job control. in fpc 3.x tprocess bugs fixed, , similar (pipe processing stalled if stderr wasn't regularly processed too, see intruncommand code).
if receiving program doesn't process stderr, don't use it.
Comments
Post a Comment