Re: redirecting output to a file with g_spawn_async



On Thursday 06 October 2005 19:16, Colossus wrote:

thanks for replying. I don not read with the Unix "read" function but
with G_IO_Channel glib functions:

static gboolean ExtractToDifferentLocation (GIOChannel *ioc,
GIOCondition cond, gpointer data)
{
      if (cond & (G_IO_IN | G_IO_PRI) )
      {
              //while (gtk_events_pending() )
                      //gtk_main_iteration();
              gchar *line = NULL;
              g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
              if (line != NULL )
              {
                      //Write the content the bzip extracted file, line after line, to
the file choosen by the user
                      fwrite ( line, 1, strlen(line) , fd );
                      g_free (line);
              }
              return TRUE;
      }
      else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
      {
              fclose ( fd );
              g_io_channel_unref (ioc);
              g_io_channel_shutdown ( ioc,TRUE,NULL );
              g_spawn_close_pid ( child_pid );
              return FALSE;
      }
}

The following things come to mind in relation to your code:

1.  Have you set the GIOChannel encoding to null (necessary to read binary 
data rather than text)?  (Read the documentation for 
g_io_channel_unix_new().)

2.  If it is binary data you are reading, then you should not use 
g_io_channel_read_line() (whether there are line marker characters in the 
data stream would be entirely arbitrary in that case).  If you insist on 
using GIOChannel then use g_io_channel_read_chars() (after turning off code 
conversion).

3.  You are not doing any error checking, and in particular you are not 
checking the return value of the GIOChannel read function.

Chris




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