X-Git-Url: http://git.roojs.org/?p=gitlive;a=blobdiff_plain;f=Spawn.vala;h=1ff51e88d106b62f67162a315197e04a49c9f9e9;hp=738ea44d6721d406cb253e35dc852d1d74a3d3ac;hb=9e641e366549656621a3e4fc4950b62c4b395650;hpb=1f7e6b712f9ee99d621a3a67f1c0795c6106bde6 diff --git a/Spawn.vala b/Spawn.vala index 738ea44d..1ff51e88 100644 --- a/Spawn.vala +++ b/Spawn.vala @@ -223,9 +223,45 @@ public class Spawn : Object if (this.cfg.debug) { - stdout.printf("cd %s; %s\n" , this.cfg.cwd , string.joinv(" ", this.cfg.args)); + GLib.debug("cd %s; %s\n" , this.cfg.cwd , string.joinv(" ", this.cfg.args)); } + // stdout: + if (!this.cfg.async) { + string ls_stdout; + string ls_stderr; + int ls_status; + + Process.spawn_sync ( + this.cfg.cwd, + this.cfg.args, + this.cfg.env, + SpawnFlags.SEARCH_PATH, + null, + out ls_stdout, + out ls_stderr, + out ls_status + ); + this.output = ls_stdout; + this.stderr = ls_stderr; + this.result = ls_status; + if (this.cfg.exceptions && this.result != 0) { + var errstr = string.joinv(" ", this.cfg.args) + "\n"; + errstr += this.output; + errstr += this.output.length > 0 ? "\n" : ""; + errstr += this.stderr; + //print("Throwing execute error:%s\n", errstr); + throw new SpawnError.EXECUTE_ERROR(errstr); + //this.toString = function() { return this.stderr; }; + ///throw new Exception this; // we throw self... + } + return; + + } + + + + Process.spawn_async_with_pipes ( this.cfg.cwd, this.cfg.args, @@ -237,14 +273,14 @@ public class Spawn : Object out standard_output, out standard_error); - // stdout: + //print(JSON.stringify(gret)); if (this.cfg.debug) { - stdout.printf("PID: %d\n" ,this.pid); + GLib.debug("PID: %d\n" ,this.pid); } this.ref(); // additional ref - cleared on tidyup... @@ -295,7 +331,7 @@ public class Spawn : Object if (this.pid > -1) { // child can exit before we get this far.. if (this.cfg.input != null) { - if (this.cfg.debug) print("Trying to call listeners"); + if (this.cfg.debug) GLib.debug("Trying to call listeners"); try { this.write(this.cfg.input()); // this probably needs to be a bit smarter... @@ -324,12 +360,14 @@ public class Spawn : Object if (this.pid > -1) { //print("starting main loop"); - //if (this.cfg.debug) { - // - // } + if (this.cfg.debug) { + GLib.debug("starting main loop"); + } this.ctx = new MainLoop (); this.ctx.run(); // wait fore exit? - + if (this.cfg.debug) { + GLib.debug(" main loop done"); + } //print("main_loop done!"); } else { this.tidyup(); // tidyup get's called in main loop. @@ -383,6 +421,10 @@ public class Spawn : Object private void tidyup() { + if (this.cfg.debug) { + GLib.debug("tidyup"); + } + //print("Tidyup\n"); if (this.pid > -1) { Process.close_pid(this.pid); // hopefully kills it..