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

VS: redirecting stdout to a text widget



> Ok, I need help on how to redirect stdout to a text widget.  I am writing
a gui type shell used in the debug mode
> of our software, and many of the libraries use printf's to make debugging
comments.  Also the commands for the
> shell that the gtk gui is executing use printf's to show their help
messages.  Anyway, I need to be able to
> redirect text that is going to stdout through the printf's to my text
widget.  I have seen some examples on
> previous lists - mostly in perl which I am unfamiliar with.  My
application is in C.  I have also seen references
> to popen, but I am not sure how to use it in my context.  I could direct
it all to a file, and then read the file,
> but it seams there would be a better way.
>


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
  printf("before\n");  // goes to the terminal as usual

  mkfifo("/tmp/foopipe", 0600);
  stdout =freopen("/tmp/foopipe", "w", stdout);

  printf("after\n");  // goes to /tmp/foopipe

  return 0;
}

And on an other terminal say "tail -f /tmp/foopipe".

Mind, however, that the writer will block until someone
reads the other end of the pipe.

Error checking may be useful too ,)


    Jonk




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