Re: g_spawn_async_with_pipes() vs system()



On Sat, 25 Oct 2008, Dan Saul wrote:

What I am trying to do is launch mplayer as a sub process to 
show a movie in one of my windows (-wid option).

Running system() works fine with the generated command line 
argument, but no such luck with g_spawn_async_with_pipes.

To generate the command line I use ... [some weird stuff]

The following works (without the -wid bit, which I can't easily 
replicate, but which you could easily add).  Connect up the pipes, 
of course, if you want them.  "name space.mpg" is in the current 
directory when the program is invoked.

#include <glib.h>
#include <stdio.h>

int sample_spawn (void)
{
    GError *error = NULL;
    gchar *argv[6];
    gint ok;

    argv[0] = "/usr/bin/mplayer";
    argv[1] = "/usr/bin/mplayer";
    argv[2] = "-msglevel";
    argv[3] = "all=9";
    argv[4] = "name space.mpg";
    argv[5] = NULL;

    ok = g_spawn_async_with_pipes (NULL,
                                   argv,
                                   NULL,
                                   0,
                                   NULL,
                                   NULL,
                                   NULL,
                                   NULL,
                                   NULL,
                                   NULL,
                                   &error);

    if (!ok) {
        fprintf(stderr, "error: '%s'\n", error->message);
        g_error_free(error);
    }

    return !ok;
}

int main (void)
{
    sample_spawn();
    return 0;
}

Allin Cottrell





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