Re: redirecting output to a file with g_spawn_async



Chris Vine wrote:
See:
man 2 read
man 3 strlen

In particular: (1) Why do you assume that the input which you have read comprises a null terminated string? (2) Have you allowed for a short read from Unix read()?

Hi Chris,
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 problem seems to be a kind of conversion on the bytes before they are being written to the file. The file is a RAR file that has bzip2 compressed. I run bzip2 -d file.bz2 with g_spawn_async_with_pipes and then as Oliver counseled me, I read with the function above and then write to the file with fwrite.

I really do not understand why I have the data corrupted and also the
file dimension longer that the original RAR file decompressed from the
shell with bzip2 -d file.bz2 !
--
Colossus

Cpsed, a Linux OpenGL 3D scene editor
http://cpsed.sourceforge.net/




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