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:
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!
You can try
g_unix_input_stream_new_from_fd(fileno(stdin), FALSE);. You might need to
#include <gio/gunixinputstream.h> for that function
FALSE is for not closing stdin when closing the input stream.
Hello thx for the answer.
That looks great, but only for UNIX system :/. No portable solution?
Anything that supports POSIX will work with that.
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
fatal error: gio/gwin32inputstream.h: No such file or directory
EDIT: oh probably need to add include path in configure files.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.