For this you should prefer the Gio.Subprocess API. Unfortunately it's too new to appear in the roojs documentation, but here's the Python documentation so you can get a sense of how it works: http://lazka.github.io/pgi-docs/index.html#Gio-2.0/classes/Subprocess.html#Gio.Subprocess
Here are how the examples from your linked StackOverflow question would be implemented. (I didn't post them there because your question was really about the main loop, so it wouldn't have been a good answer for SO.) Sync: const Gio = imports.gi.Gio; let subprocess = new Gio.Subprocess({ argv: ['/bin/ls'], flags: Gio.SubprocessFlags.STDOUT_PIPE, }); subprocess.init(null); let [, out] = subprocess.communicate_utf8(null, null); print(out); Async: const Gio = imports.gi.Gio; const Mainloop = imports.mainloop; let subprocess = new Gio.Subprocess({ argv: ['/bin/ls'], flags: Gio.SubprocessFlags.STDOUT_PIPE, }); subprocess.init(null); subprocess.communicate_utf8_async(null, null, (obj, res) => { let [, out] = obj.communicate_utf8_finish(res); print(out); Mainloop.quit('main'); }); Mainloop.run('main'); Regards, Philip On Wed, Dec 9, 2015 at 2:05 PM Andrea Giammarchi < andrea.giammar...@gmail.com> wrote: > there are few examples to consider: > > 1. https://github.com/optimisme/gjs-examples/blob/master/egSpawn.js > 2. > > http://git.roojs.org/?p=gitlive;a=blob;f=Spawn.js;h=4d9f202373cb111b47cb3c2eac0db4de405e0deb;hb=HEAD > 3. > https://github.com/WebReflection/jsgtk/blob/master/jsgtk/fs.js#L9-L22 > (for files and without pipes) > > Hope one of these helps > > > On Sat, Oct 31, 2015 at 1:11 PM, muhammed hassan <muhammedabu...@gmail.com > > wrote: > >> Hello, >> I am trying to read stdout form gjs asynchronously and I failed . >> here is my question on stack overflow . >> read-asynchronous-stdout-from-gjs >> <http://stackoverflow.com/questions/33451496/read-asynchronous-stdout-from-gjs> >> >> any help is much appreciated. >> thanks >> >> _______________________________________________ >> javascript-list mailing list >> javascript-list@gnome.org >> https://mail.gnome.org/mailman/listinfo/javascript-list >> >> > _______________________________________________ > javascript-list mailing list > javascript-list@gnome.org > https://mail.gnome.org/mailman/listinfo/javascript-list >
_______________________________________________ javascript-list mailing list javascript-list@gnome.org https://mail.gnome.org/mailman/listinfo/javascript-list