Reading input from piped stdin.
Thomas
sitronvask at gmail.com
Fri Feb 14 11:05:01 PST 2014
I'm new to D, and I find it quite enjoyable so far.
I have however stumbled upon a problem which I can't seem to
figure out.
I am trying to make a program that creates a child process,
writes something to the child process stdin and reading from its
stdout. I am going to use it later for testing out process pair
redundancy.
Appearently the child blocks at "s = stdin.readln()". If I remove
all writing to the child, and instead just read its output,
everything works fine. My code is attached below:
import std.process,std.stdio,std.getopt,core.thread;
void main(string[] args){
bool backup = false;
getopt(args, "backup", &backup);
writeln("Something worked!");
string s = "test";
if (backup){
writeln("Backup up & running");
while(true){
s = stdin.readln();
writeln(s);
}
}
auto pipes = pipeProcess(["./pipetest", "--backup"],
Redirect.all);
for(int j = 0; j<5; j++){
writeln(j);
pipes.stdin.writeln(j);
writeln(pipes.stdout.readln());
Thread.sleep(500.msecs);
}
while(true){}
}
If anyone could spot what rudimentary mistake I have done, I
would greatly appreciate it. Alternatively, suggesting another
way to implement inter-process communication would also be
appreciated :D
More information about the Digitalmars-d-learn
mailing list