std.process: how to process stdout chunk by chunk without waiting for process termination

Timothee Cour thelastmammoth at gmail.com
Tue Jun 18 14:41:57 PDT 2013


I'd like to do the following:

auto pipes = pipeShell(command, Redirect.stdout | Redirect.stderr);

while(true){
version(A1)
  string line=pipes.stdout.readln;
version(A2)
  auto line=pipes.stdout.readChunk(10);
version(A3)
  auto line=pipes.stdout.readChar();

  // do something with line

  if(tryWait(pipes.pid).terminated)
    break;
}


The problem is that 'string line=pipes.stdout.readln;' seems to block until
the process is terminated, ie if the command is a long running command that
prints a line every 1 second for 10 seconds, this program will wait 10
seconds before starting the processing.
I also tried with rawRead, readf, fgetc but couldn't make it work.
I'm on OSX, if that matters.

Is there any way to achieve this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130618/79ef3cdc/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list