Binary writing to an input pipe and ASCII reading from an output one
- From: Colossus <colossus 3000 it>
- To: gtk-app-devel-list gnome org
- Subject: Binary writing to an input pipe and ASCII reading from an output one
- Date: Mon, 24 Oct 2005 15:36:13 -0700
Hi,
I'm trying without success to implement cat /tmp/file.cpio | cpio -tv
with g_spawn family and giochannels. My code is to use
"g_spawn_async_with_pipes" with both input and output pipes the "cpio
-tv" command and then I open in read mode the binary cpio archive (I
don't spawn cat just use g_io_channel_new_file):
gchar buffer[65536];
gsize bytes_read;
GError *error = NULL;
GIOChannel *ioc , *input_ioc;
compressor_pid = SpawnAsyncProcess ( "cpio -tv" , 0 , 1);
if ( compressor_pid == 0 )
{
unlink ( tmp );
g_free (tmp);
return;
}
SetIOChannel (error_fd,
G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,GenError, NULL );
SetIOChannel (output_fd,
G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,ReadCPIOOutput, NULL );
input_ioc = SetIOChannel (input_fd, G_IO_IN|G_IO_PRI , NULL, NULL);
//The second parameter is set to NULL because the CPIO archive is
binary
g_io_channel_set_encoding (input_ioc, NULL , NULL);
//tmp contains the filename of the binary cpio archive
ioc = g_io_channel_new_file ( tmp , "r" , NULL );
g_io_channel_set_encoding (ioc, NULL , NULL);
g_io_channel_set_flags ( ioc , G_IO_FLAG_NONBLOCK , NULL );
while ( g_io_channel_read_chars ( ioc, buffer, sizeof(buffer),
&bytes_read, &error ) == G_IO_STATUS_NORMAL )
{
if ( error != NULL )
{
g_print ("Read Error: %s\n",error->message);
g_error_free ( error );
g_io_channel_shutdown ( ioc,TRUE,NULL );
g_io_channel_unref (ioc);
g_spawn_close_pid ( child_pid );
g_free (tmp);
}
status = g_io_channel_write_chars ( input_ioc , buffer ,
sizeof(buffer) , NULL , &error );
if ( status == G_IO_STATUS_ERROR )
{
g_print ("Write Error: %s\n",error->message);
g_error_free ( error );
g_io_channel_shutdown ( ioc,TRUE,NULL );
g_io_channel_unref (ioc);
g_spawn_close_pid ( child_pid );
g_free (tmp);
}
}
Sometimes the console gives no output but the output of the command
cpio (redirected in a GtkTextBuffer) is:
cpio: warning: skipped 7099 bytes of junk
cpio: warning: skipped 13776 bytes of junk
cpio: warning: skipped 22769 bytes of junk
cpio: warning: skipped 104333 bytes of junk
while some other times the output (the list of files in the cpio
archive) is incomplete. I believed is was a matter of encoding but the
cpio archive is binary I'm sure of this while its ouput is ASCII and I
have correctly set the encoding, so what can be ?
--
Colossus
Xarchiver, a GTK2 only archive manager - http://xarchiver.sourceforge.net
Cpsed, a Linux OpenGL 3D scene editor - http://cpsed.sourceforge.net
Mizio, a QT proxy hunter scanner tool - http://mizio.sourceforge.net
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]