Re: redirecting output to a file with g_spawn_async
- From: Andreas Stricker <andreas stricker fela ch>
- To: gtk-app-devel-list gnome org
- Subject: Re: redirecting output to a file with g_spawn_async
- Date: Thu, 06 Oct 2005 12:24:49 +0200
Colossus wrote:
g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
if (line != NULL )
{
fwrite ( line, 1, strlen(line) , fd );
g_free (line);
}
Come on, read this code carefully: If you assume that you alway extract
text-only data, it's ok. But in all other case, you read in a line
and write the data from line buffer start to the first including null
byte to fd. That is really not what you want.
Use a not text file base read methode like g_io_channel_read_chars()
then read into a fixed size buffer and write all read bytes into the
final file.
gchar buf[4096];
gsize read_bytes;
GError *err = NULL;
g_io_channel_read_chars(ioc, buf, sizeof(buf), &read_bytes, &err);
if ( err != NULL && read_bytes > 0)
fwrite(buf, sizeof(gchar), read_bytes, fd);
/* you may add more error handling here */
Cheers, Andy
--
FELA Management AG Phone :+41-52-646 46 55
Basadingerstrasse 18 Fax :+41-52-646 46 96
CH-8253 Diessenhofen mailto:andreas stricker fela ch
http://www.fela.ch/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]