use task::spawn_sched to read stdout and stderr at the same time

Hopefully this addresses the root cause of the hangs when running make check on windows.
This commit is contained in:
Ted Horst 2012-02-10 10:03:34 -06:00 committed by Brian Anderson
parent a7a1152db5
commit 9fde2a54f4

View file

@ -52,10 +52,33 @@ fn run(lib_path: str, prog: str, args: [str],
writeclose(pipe_in.out, input);
let p = comm::port();
let ch = comm::chan(p);
task::spawn_sched(1u) {||
let errput = readclose(pipe_err.in);
comm::send(ch, (2, errput));
};
task::spawn_sched(1u) {||
let output = readclose(pipe_out.in);
comm::send(ch, (1, output));
};
let status = run::waitpid(pid);
ret {status: status, out: output, err: errput};
let errs = "";
let outs = "";
let count = 2;
while count > 0 {
let stream = comm::recv(p);
alt stream {
(1, s) {
outs = s;
}
(2, s) {
errs = s;
}
};
count -= 1;
};
ret {status: status, out: outs, err: errs};
}
fn writeclose(fd: fd_t, s: option<str>) {