stdout.printf("PID: %d" ,this.pid);
}
+ this.ref(); // additional ref - cleared on tidyup...
+
this.in_ch = new GLib.IOChannel.unix_new(standard_input);
this.out_ch = new GLib.IOChannel.unix_new(standard_output);
this.err_ch = new GLib.IOChannel.unix_new(standard_error);
- // using NONBLOCKING only works if io_add_watch
+ // using NONBLOCKING only works if io_add_watch
//returns true/false in right conditions
this.in_ch.set_flags (GLib.IOFlags.NONBLOCK);
this.out_ch.set_flags (GLib.IOFlags.NONBLOCK);
this.out_src = (int) this.out_ch.add_watch (
IOCondition.OUT | IOCondition.IN | IOCondition.PRI | IOCondition.HUP | IOCondition.ERR ,
(channel, condition) => {
- return this.read(this.out_ch);
+ return this.out_ch != null ? this.read(this.out_ch) : true;
}
);
this.err_src = (int) this.err_ch.add_watch (
IOCondition.OUT | IOCondition.IN | IOCondition.PRI | IOCondition.HUP | IOCondition.ERR ,
(channel, condition) => {
- return this.read(this.err_ch);
+ return this.err_ch != null ? this.read(this.err_ch) : true;
}
);
private void tidyup()
{
+ this.unref();
if (this.pid > -1) {
Process.close_pid(this.pid); // hopefully kills it..
this.pid = -1;
return str.length;
}
-
-
+
/**
* read from pipe and call appropriate listerner and add to output or stderr string.
{
string prop = (ch == this.out_ch) ? "output" : "stderr";
// print("prop: " + prop);
-
+
//print(JSON.stringify(ch, null,4));
while (true) {
size_t term_pos;
size_t len;
IOStatus status;
+
+ if (this.pid < 0) {
+ return false; // spawn complete + closed... can't read any more.
+ }
+
try {
+ var cond = ch.get_buffer_condition();
+ if ((cond & GLib.IOCondition.ERR) > 0) {
+ return false;
+ }
+ if ((cond & GLib.IOCondition.IN) < 1) {
+ return false;
+ }
status = ch.read_line( out buffer, out len, out term_pos );
} catch (Error e) {
//FIXme
- break; // ??
+ return false;
}