this.env = env;
async = false;
- exceptions = false;
+ exceptions = true;
debug = false;
output = null;
input = null;
}
-
- public void setOptions(
- bool async,
- bool exceptions,
- bool debug
- ) {
- this.async = async;
- this.exceptions = exceptions;
- this.debug = debug;
- }
+
+
public void setHandlers(
SpawnOutput? output,
SpawnErr? stderr,
this.cfg = cfg;
-
+ this.output = "";
+ this.stderr = "";
this.cfg.cwd = this.cfg.cwd.length < 1 ? GLib.Environment.get_home_dir() : this.cfg.cwd;
if (this.cfg.args.length < 0) {
/**
* @property output {String} resulting output
*/
- public string output = "";
+ public string output;
/**
* @property stderr {String} resulting output from stderr
*/
- public string stderr = "";
+ public string stderr;
/**
* @property result {Number} execution result.
*/
out this.pid,
out standard_input,
out standard_output,
- out standard_error);
+ out standard_error);
// stdout:
stdout.printf("PID: %d" ,this.pid);
}
-
+
+ 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);
+
+ // make everything non-blocking!
+
+
+
+ // 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.err_ch.set_flags (GLib.IOFlags.NONBLOCK);
+
+
+
+
ChildWatch.add (this.pid, (w_pid, result) => {
this.result = result;
- 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);
-
- // make everything non-blocking!
-
-
-
- // 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.err_ch.set_flags (GLib.IOFlags.NONBLOCK);
-
-
+
// add handlers for output and stderr.
}
);
this.err_src = (int) this.err_ch.add_watch (
- IOCondition.OUT | IOCondition.IN | IOCondition.PRI | IOCondition.HUP | IOCondition.ERR ,
+ IOCondition.OUT | IOCondition.IN | IOCondition.PRI | IOCondition.HUP | IOCondition.ERR ,
(channel, condition) => {
return this.read(this.err_ch);
}
// start mainloop if not async..
if (this.pid > -1) {
- if (this.cfg.debug) {
- print("starting main loop");
- }
+ print("starting main loop");
+ //if (this.cfg.debug) {
+ //
+ // }
this.ctx = new MainLoop ();
this.ctx.run(); // wait fore exit?
- //print("main_loop done!");
+ print("main_loop done!");
} else {
this.tidyup(); // tidyup get's called in main loop.
}
return str.length;
}
+
+
/**
* read from pipe and call appropriate listerner and add to output or stderr string.
//}
if (ch == this.out_ch) {
this.output += buffer;
- this.cfg.output( buffer);
+ if (this.cfg.output != null) {
+ this.cfg.output( buffer);
+ }
} else {
this.stderr += buffer;
}
//_this[prop] += x.str_return;
- if (this.cfg.debug) {
+ //if (this.cfg.debug) {
stdout.printf("%s : %s", prop , buffer);
- }
+ //}
if (this.cfg.async) {
if ( Gtk.events_pending()) {