Re: GIOChannel & Intercepting stdout

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

 



On Wed, 25 Aug 2010 12:31:53 +0200
richard boaz <ivor.boaz@xxxxxxxxx> wrote:
[snip]
> My reading of GIOChannel functionality renders my usage understanding
> to be:
> 
>    - create a channel using the file descriptor (in this case
> STDOUT_FILENO)
>    - add a watch on the conditions of interest (in this case G_IO_IN)
>    - start the main loop
>    - read the data on the channel within my callback and process
> accordingly
> 
> Which, I think, would result in:
> 
>    - the callback being called with condition G_IO_IN whenever
> anything is written to stdout
> 
> Except that I don't experience anything close to this result.
> 
> Below is sample code demonstrating what I'm trying to achieve here,
> but basically, it:
> 
>    - creates a GIOChannel on stdout
>    - adds a watch on condition G_IO_IN
>    - adds an idle routine to write a message to stdout
>    - starts the main loop
> 
> As I said, what I would expect from this:
> 
>    - callback fired with condition G_IO_IN when idle call writes to
> stdout
> 
> However, when this executes, I get:
> 
>    - the test message output to the terminal (completely bypassing the
>    callback routine)
>    - the callback gets fired only after the <ENTER> key is hit on the
>    keyboard, with nothing to be read from the channel.  (huh?...)

This won't work.  file descriptor number 1 (stdout) is a file descriptor
you write to, not read from.

If you connect stdout to the write file descriptor of a pipe with
dup2(), and then connect your GIOChannel object to the read file
descriptor of the pipe, it should work.  Whether it does or not will
depend on the libraries which you say are writing to stdout.  If they
expect a terminal on stdout you may need to resort to pseudo-ttys.

Chris


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


[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux