+/// # valac --pkg gio-2.0 --pkg gtk+-3.0 --pkg posix Spawn.vala -o /tmp/Spawn
using GLib;
+using Gtk;
// compile valac
-/// # valac --pkg gio-2.0 --pkg posix Spawn.vala -o /tmp/Spawn
///using Gee; // for array list?
}
- bool ctx = false; // the mainloop ctx.
+ MainLoop ctx = null; // the mainloop ctx.
/**
* @property output {String} resulting output
if (this.cfg.debug) {
- stdout.print("PID: %d" ,this.pid);
+ stdout.printf("PID: %d" ,this.pid);
}
ChildWatch.add (this.pid, (w_pid, result) => {
this.result = result;
- if (this.debug) {
- print("child_watch_add : result:%d ", result);
+ if (this.cfg.debug) {
+ stdout.printf("child_watch_add : result:%d ", result);
}
this.read(this.out_ch);
//print("write_char retunred:" + JSON.stringify(res) + ' ' +JSON.stringify(ret) );
- if (res != GLib.IOStatus.NORMAL) {
- throw "Write failed";
+ if (res != GLib.IOStatus.NORMAL) {
+ throw "Write failed";
}
//return ret.value;
return str.length;
string prop = (ch == this.out_ch) ? "output" : "stderr";
// print("prop: " + prop);
var _this = this;
+ string str_return;
-
//print(JSON.stringify(ch, null,4));
while (true) {
-
- var x = {};
- var status = ch.read_line( x);
+ string buffer;
+ size_t term_pos;
+ size_t len;
+ IOStatus status;
+ try {
+ status = ch.read_line( out buffer, out len, out term_pos );
+ } catch (Error e) {
+ //FIXme
+ break; // ??
+
+ }
// print('status: ' +JSON.stringify(status));
// print(JSON.stringify(x));
switch(status) {
case GLib.IOStatus.NORMAL:
//write(fn, x.str);
- if (this.listeners[prop]) {
- this.listeners[prop].call(this, x.str_return);
+ //if (this.listeners[prop]) {
+ // this.listeners[prop].call(this, x.str_return);
+ //}
+ if (ch == this.out_ch) {
+ this.output += buffer;
+ } else {
+ this.stderr += buffer;
}
- _this[prop] += x.str_return;
- if (_this.debug) {
- print(prop + ':' + x.str_return.replace(/\n/, ''));
+ //_this[prop] += x.str_return;
+ if (this.cfg.debug) {
+ stdout.printf("%s : %s", prop , str_return);
}
- if (this.async) {
+ if (this.cfg.async) {
try {
- if (imports.gi.Gtk.events_pending()) {
- imports.gi.Gtk.main_iteration();
+ if ( Gtk.events_pending()) {
+ Gtk.main_iteration();
}
} catch(Error e) {