Re: redirecting output to a file with g_spawn_async

or you could do the following I think :)

static void
stdout_setup_func(gpointer data)
        int* fd = (int*)data;
        dup2(*fd, 1);

        int fd = open(/*open the file you want to write to*/);
        /* pass the stdin_setup_func to gspawn */
       gint stdout = 0, stderr = 0;
       g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH
|                                    G_SPAWN_LEAVE_DESCRIPTORS_OPEN |
        stdout_setup_func, &fd, NULL, NULL, &stdout, &stderr, NULL));

So when gspawn creates the child it runs the child stdout func thing
and connects the child stdout to your file descriptor and all the
output goes to file.

It's all along the lines of this post i saw. gnome org/msg00323.html

Hope this helps


On 01/10/05, Olivier Sessink <lists olivier pk wau nl> wrote:
Colossus wrote:

I tried with g_spawn_async_with_pipes and with gspawn_async
but it does not work. In the first case the output (the decompressed
bzip2 file) is redirected to a GTK window so I used g_spawn_async (no
pipes) but the output is directed to the shell window from which I ran
my program. How can I have the output redirected to the file /mnt/foo ?

open a file in write mode, and while reading from the pipe from
_spawn_async, write data to that file.


gtk-app-devel-list mailing list
gtk-app-devel-list gnome org

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