interacting with a process with redirected stdin/stdout/stderr

Timothee Cour thelastmammoth at gmail.com
Sun Jul 14 20:48:41 PDT 2013


I'm trying to interact with a process using std.process and
redirected stdin/stdout/stderr.
What would be the recommended way?

For example:
----
auto pipes=pipeShell("myprocess",Redirect.all);
while(true){
  pipes.stdin.rawWrite(some_command);
  foreach (line; pipes.stdout.byLine) {
    //do something with line
  }
}
----

This doesn't work because it might block inside pipes.stdout.byLine, as the
process is requesting more inputs to be written to its stdin before
outputting more bytes to its stdout.

What's the right approach?
* fcntl(fd, F_SETFL, O_NONBLOCK); didn't seem to work
* reading pipes.stdout inside a separate thread?
In that second case, how to cleanly dispose of a blocked thread when we no
longer need it?

Any detailed example would help.
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130714/d5551886/attachment.html>


More information about the Digitalmars-d-learn mailing list