Re: how to read from UnixInputStream



Il giorno mar, 13/12/2011 alle 21.11 +0800, binbin ha scritto:
> I'm tring to spawn a command and read its output. In the sync way, I
> find imports.gi.GLib.spawn_command_line_sync is fine. But in the async
> way, I cannot find any information on dealing with the unix file
> descriptor.
> 
> try the code below:
> 
> glib = imports.gi.GLib;
> cmd = 'uname -a';
> [success,argc,argv] = glib.shell_parse_argv(cmd);
> [success,pid,stdin,stdout,stderr] =
> glib.spawn_async_with_pipes(null,argv,null,glib.SpawnFlags.SEARCH_PATH,null,null);
> gio = imports.gi.Gio;
> stream = new gio.UnixInputStream({fd:stdout});
> 
> we can get a UnixInputStream, but I don't know how to use the read
> method. The g_input_stream_read indicates that there should be 3
> parameters, a buffer(void*), a count(gsize), a cancellable
> object(GCancellable). Then, what's the corressponding type for void* in
> gjs?

In that case, it would be an Array (and should be a return value).
Unfortunately, in gobject-introspection the method has a gpointer, which
gjs cannot represent.
If you need to read text, you should wrap the UnixInputStream in a
DataInputString and use g_data_input_stream_read_line(). If you need to
read a binary array, file a bug at glib and ask for a type override
annotation.

Giovanni

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]