On Monday 30 May 2005 13:31, Colossus wrote:

> I'm trying to catch the returned error message of the unzip
> executable with GIOChannel. I use g_spawn_async_with_pipes and
> then I create a GIOChannel and then i call g_io_add_watch. I run
> unzip with an incomplete zip file so the unzip executable
> fails with an error message but the G_IO_ERR condition is never met,
> while the G_IO_HUP is met when both the pipe ends and when the unzip
> returns an error; how can I distinguish the two conditions so to have
> my application emits an appropriate gtk_dialog with an error message
> when unzip fails to open the zip archive ?

The G_IO_ERR condition only occurs if there is an error on the pipe/iochannel. 
It has nothing to do with the child program being executed. To catch an error 
in your spawned unzip program, you'll need to:

 * pass the G_SPAWN_DO_NOT_REAP_CHILD flag to g_spawn_*
 * watch the child yourself via g_child_watch_add ()

When the child exits, the callback function you passed to g_child_watch_add() 
is called with the exit status of the child, which will tell you if the child 
exited with an error or not. On unix, you'll need the macros described in the 
waitpid manpage to interpret the exit code (e.g. if (WIFEXITED(status) && 
WEXITSTATUS(status) == EXIT_SUCCESS) then it's a normal exit, otherwise there 
was an error or the program received a fatal signal). No idea how to 
interpret the exit code on win32.

Alternatively, or in addition, you could just watch stderr for messages, and 
assume that an error has occured if unzip prints a message to stderr.

Cheers
 -Tim

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to