X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=blobdiff_plain;f=src%2FSpawn.vala;h=d3b9428b9f96ef5d841aed9c3892683eb9bdfc26;hp=887715be8b3126b080156e4754bf8e42762fc072;hb=7e857d8072408ca9f7a3384f2bff241200b5991c;hpb=3e94bca5bcb897c36bafcc68956bc7b2595bd39f diff --git a/src/Spawn.vala b/src/Spawn.vala index 887715be8..d3b9428b9 100644 --- a/src/Spawn.vala +++ b/src/Spawn.vala @@ -43,10 +43,7 @@ public errordomain SpawnError { * */ - - -public delegate void SpawnFinish (int res, string str, string stderr); - + public class Spawn : Object { /** @@ -55,10 +52,10 @@ public class Spawn : Object */ public signal string? input(); /** - * @signal input called at start to send input when process starts? - * @return the string or null + * @signal complete called at when the command has completed. + * */ - public signal void complete(); + public signal void complete(int res, string str, string stderr); /** * @signal output_line called when a line is recieved from the process. * Note you may want to connect this and run @@ -74,6 +71,7 @@ public class Spawn : Object public bool is_async = true; public bool throw_exceptions = false; + public bool detach = false; public Spawn(string cwd, string[] args) throws Error { @@ -156,11 +154,27 @@ public class Spawn : Object GLib.debug("cd %s; %s" , this.cwd , string.joinv(" ", this.args)); - + if (this.detach) { + Process.spawn_async_with_pipes ( + this.cwd, + this.args, + this.env.length > 0 ? this.env : null, + SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, + null, + out this.pid); + ChildWatch.add (this.pid, (pid, status) => { + // Triggered when the child indicated by child_pid exits + Process.close_pid (pid); + + }); + + return; + + } Process.spawn_async_with_pipes ( this.cwd, this.args, - this.env, + this.env.length > 0 ? this.env : null, SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, null, out this.pid, @@ -169,7 +183,7 @@ public class Spawn : Object out standard_error); // stdout: - + //print(JSON.stringify(gret)); @@ -212,7 +226,7 @@ public class Spawn : Object this.tidyup(); //print("DONE TIDYUP"); - finish(this.result, this.output, this.stderr); + this.complete(this.result, this.output, this.stderr); }); @@ -357,7 +371,7 @@ public class Spawn : Object */ private bool read(IOChannel ch) { - string prop = (ch == this.out_ch) ? "output" : "stderr"; + // string prop = (ch == this.out_ch) ? "output" : "stderr"; // print("prop: " + prop); @@ -391,10 +405,11 @@ public class Spawn : Object } else { this.stderr += buffer; + this.output_line( buffer); } //_this[prop] += x.str_return; //if (this.cfg.debug) { - GLib.debug("%s : %s", prop , buffer); + //GLib.debug("%s : %s", prop , buffer); //} if (this.is_async) {