* Library to wrap GLib.spawn_async_with_pipes
*
* usage:
-*
-* Spawn = import.Spawn;
-*
-* simple version..
-* var output = Spawn.run({
-* cwd : '/home',
-* args : [ 'ls', '-l' ],
-* env : [], // optional
-* listeners : {
- output : function (line) { Seed.print(line); },
-* stderr : function (line) {Seed.print("ERROR" + line); },
-* input : function() { return 'xxx' },
-* }
-* });
-*
-*
+* v
*
-*
-*
-*var output = Spawn.run( SpawnConfig() {
+*var output = new Spawn( SpawnConfig() {
cwd = "/home", // empty string to default to homedirectory.
args = {"ls", "-l" },
evn = {},
delegate string SpawnInput();
-
-struct SpawnConfig
+
struct SpawnConfig {
public string cwd;
public string[] args;
if (!this.cfg.args.length) {
throw "No arguments";
}
+ this.run();
}
* @arg str {String} string to write to stdin of process
* @returns GLib.IOStatus (0 == error, 1= NORMAL)
*/
- public void write(str) // write a line to
+ integer write(str) // write a line to
{
if (this.in_ch is null) {
return 0; // input is closed
//return ret.value;
return str.length;
- },
+ }
/**
* read from pipe and call appropriate listerner and add to output or stderr string.
}
};
-/**
- * @function run
- *
- * simple run a process - returns result, or throws stderr result...
- * @param cfg {Object} see spawn
- * @return {string} stdout output.
- */
-function run(cfg) {
- cfg.exceptions = true;
- cfg.async = false;
- var s = new Spawn(cfg);
- var ret = s.run();
- return s.output;
-}
- /*
+ /*
// test
try {
Seed.print(run({