/**
* Revised version?
*
- * x = new Spawn( working dir, args)
+ * x = new Spawn( "/tmp", {"ls", "-l" })
*
* // these are optionall..
* x.env = ..... (if you need to set one...
- * x.output_line.connect((string str) => { ... });
+ * x.output_line.connect((string str) => {
+ * if ( Gtk.events_pending()) { Gtk.main_iteration(); }
+ * });
* x.input_line.connect(() => { return string });
*
* x.run((int res, string output, string stderr) => { ... });
*
*/
-
-
-delegate void SpawnFinish (int res, string str, string stderr);
-
+
public class Spawn : Object
{
/**
* @return the string or null
*/
public signal string? input();
+ /**
+ * @signal complete called at when the command has completed.
+ *
+ */
+ 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
public bool is_async = true;
public bool throw_exceptions = false;
+ public bool detach = false;
public Spawn(string cwd, string[] args) throws Error
{
* result is applied to object properties (eg. '?' or 'stderr')
* @returns {Object} self.
*/
- public void run(SpawnFinish finish) throws SpawnError, GLib.SpawnError, GLib.IOChannelError
+ public void run( ) throws SpawnError, GLib.SpawnError, GLib.IOChannelError
{
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,
out standard_error);
// stdout:
-
+
//print(JSON.stringify(gret));
this.tidyup();
//print("DONE TIDYUP");
- finish(this.result, this.output, this.stderr);
+ this.complete(this.result, this.output, this.stderr);
});
*/
private bool read(IOChannel ch)
{
- string prop = (ch == this.out_ch) ? "output" : "stderr";
+ // string prop = (ch == this.out_ch) ? "output" : "stderr";
// print("prop: " + prop);
} 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) {
}
}
+/*
int main (string[] args) {
GLib.Log.set_handler(null,
return 0;
}
-
+ */