public delegate void SpawnOutput(string line);
public delegate void SpawnErr(string line);
public delegate string SpawnInput();
-public delegate void SpawnFinish(int result);
+public delegate void SpawnFinish(int result, string output);
public class SpawnConfig {
public SpawnOutput output;
public SpawnErr stderr;
public SpawnInput input;
- public SpawnFinish finish;
+
// defaults..
public SpawnConfig(string cwd,
string[] args,
input = null;
}
+
+ public void onFinish( SpawnFinish? finish ) {
+ this.finish = finish;
+ }
public void setHandlers(
SpawnOutput? output,
SpawnErr? stderr,
- SpawnInput? input,
- SpawnFinish? finish
+ SpawnInput? input
+
) {
this.output = output;
this.stderr = stderr;
this.input = input;
- this.finish = finish;
+
}
if (this.cfg.args.length < 0) {
throw new SpawnError.NO_ARGS("No arguments");
}
- this.run();
+ if (!this.cfg.async) {
+ this.run((res, output) => { });
+ }
}
* result is applied to object properties (eg. '?' or 'stderr')
* @returns {Object} self.
*/
- public void run() throws SpawnError, GLib.SpawnError, GLib.IOChannelError
+ public void run(unowned SpawnFinish? finished_cb) throws SpawnError, GLib.SpawnError, GLib.IOChannelError
{
//but... let's close input now..
this.in_ch.shutdown(true);
this.in_ch = null;
-
+
} catch (Error e) {
this.tidyup();
//if (this.cfg.debug) {
//
// }
- this.ctx = new MainLoop ();
+ this.ctx = MainLoop ();
this.ctx.run(); // wait fore exit?
//print("main_loop done!");
if (this.cfg.exceptions && this.result != 0) {
-
- var errstr = this.output;
- errstr += errstr.length > 0 ? "\n" : "";
+ var errstr = string.joinv(" ", this.cfg.args) + "\n";
+ errstr += this.output;
+ errstr += this.output.length > 0 ? "\n" : "";
errstr += this.stderr;
- throw new SpawnError.EXECUTE_ERROR(errstr);
+ //print("Throwing execute error:%s\n", errstr);
+ throw SpawnError.EXECUTE_ERROR(errstr);
//this.toString = function() { return this.stderr; };
///throw new Exception this; // we throw self...
}
-
// finally throw, or return self..
-
return;
}
{
string prop = (ch == this.out_ch) ? "output" : "stderr";
// print("prop: " + prop);
-
+ //print ("spawn.read: %s\n", prop);
//print(JSON.stringify(ch, null,4));
while (true) {
try {
var cond = ch.get_buffer_condition();
- if ((cond & GLib.IOCondition.ERR) > 0) {
- return false;
- }
- if ((cond & GLib.IOCondition.IN) < 1) {
- return false;
- }
+ //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
return false;
}
-
+ if (buffer == null) {
+ return false;
+ }
+ //print("got buffer of %s\n", buffer);
// print('status: ' +JSON.stringify(status));
// print(JSON.stringify(x));
switch(status) {
}
//_this[prop] += x.str_return;
//if (this.cfg.debug) {
- stdout.printf("%s : %s", prop , buffer);
+ // stdout.printf("%s : %s", prop , buffer);
//}
if (this.cfg.async) {
if ( Gtk.events_pending()) {
Gtk.main_iteration();
}
-
}
//this.ctx.iteration(true);