Re: read asynchronous stdout from gjs
- From: philip chimento gmail com
- To: Andrea Giammarchi <andrea giammarchi gmail com>, muhammed hassan <muhammedabuali gmail com>
- Cc: javascript-list <javascript-list gnome org>
- Subject: Re: read asynchronous stdout from gjs
- Date: Thu, 10 Dec 2015 03:50:05 +0000
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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]