lock042
(Cyril Richard)
January 1, 2021, 12:47pm
1
Hello.
Is there a (easy or not) way to read stdin (FILE *) into GInputStream.
Indeed, my code want to read both from a FILE or from stdin.
From a file it is quite straightforward:
GError *error;
GFile *file = g_file_new_for_path(main_option_script);
input_stream = (GInputStream *)g_file_read(file, NULL, &error);
but not from stdin.
Cheers, and happy new year!
jensgeorg
(Jens Georg)
January 1, 2021, 1:27pm
2
You can try g_unix_input_stream_new_from_fd(fileno(stdin), FALSE);
. You might need to #include <gio/gunixinputstream.h>
for that function
The FALSE
is for not closing stdin when closing the input stream.
1 Like
lock042
(Cyril Richard)
January 1, 2021, 2:16pm
3
Hello thx for the answer.
That looks great, but only for UNIX system :/. No portable solution?
ebassi
(Emmanuele Bassi)
January 1, 2021, 2:17pm
4
Anything that supports POSIX will work with that.
1 Like
lock042
(Cyril Richard)
January 1, 2021, 4:41pm
5
Thank you both.
On windows I will use: https://developer.gnome.org/gio//2.42/gio-GWin32InputStream.html#g-win32-input-stream-new
However, even with checking
Run-time dependency glib-2.0 found: YES 2.66.4
Run-time dependency gio-2.0 found: YES 2.66.4
Run-time dependency gio-windows-2.0 found: YES 2.66.4
I have
fatal error: gio/gwin32inputstream.h: No such file or directory
EDIT: oh probably need to add include path in configure files.
system
(system)
Closed
January 15, 2021, 4:41pm
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.