home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / windows / x / motif / 5572 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  3.2 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!ames!uakari.primate.wisc.edu!usenet.coe.montana.edu!rpi!batcomputer!snake.tc.cornell.edu!reed
  2. From: reed@snake.tc.cornell.edu (Michael G. Reed)
  3. Newsgroups: comp.windows.x.motif
  4. Subject: Re: stderr and stdout to XmText widget
  5. Keywords: stderr stdout XmText
  6. Message-ID: <1992Aug12.192500.15056@tc.cornell.edu>
  7. Date: 12 Aug 92 19:25:00 GMT
  8. References: <1992Aug12.172834.21325@Veritas.COM>
  9. Sender: news@tc.cornell.edu
  10. Reply-To: reed@Theory.TC.Cornell.EDU
  11. Distribution: comp.windows.x.motif
  12. Organization: Cornell National Supercomputing Facility
  13. Lines: 83
  14. Nntp-Posting-Host: snake.tc.cornell.edu
  15.  
  16.  
  17. Here's some code I used not to long ago.  It pipes stderr/stdout from it's
  18. child processes to a text widget (assumes the text widget is already created
  19. and called "console", a global), but it's easily modified to do it for the
  20. current app (as a matter of fact, I think the changes I just did will snag
  21. the current app).  Hope this helps.
  22.  
  23. -Michael
  24.  
  25.  
  26.  
  27. int             child_pipe[2];
  28. FILE           *from_console;
  29. FILE           *to_console;
  30. Widget        top_level;  /* toplevel shell */
  31. Widget          console;    /* your text widget */
  32.  
  33. {
  34.     if (pipe (child_pipe))
  35.     {
  36.         fprintf (stderr, "%s: Could not open child pipe.\n", progname);
  37.         exit (PIPE_ERROR);
  38.     }
  39.     to_console = fdopen (child_pipe[1], "w");
  40.     from_console = fdopen (child_pipe[0], "r");
  41.     XtAppAddInput (XtWidgetToApplicationContext (toplevel), child_pipe[0],
  42.                (XtPointer) XtInputReadMask, output_from_child, NULL);
  43.  
  44. /* These two lines can apply to your current app, or children...nice for getting
  45.    stderr/stdout from child processes */
  46.  
  47.     if ((n1 = dup2 (child_pipe[1], 1)) == -1)
  48.         fprintf (stderr, "%s: Failed to duplicate to stdout.\n", progname);
  49.     if ((n2 = dup2 (child_pipe[1], 2)) == -1)
  50.         fprintf (stderr, "%s: Failed to duplicate to stderr.\n", progname);
  51. }
  52.  
  53.  
  54. void
  55. output_from_child ()
  56.  
  57. {
  58.  
  59.         int             fd,
  60.                     dummy = 0,
  61.                         oldstat;
  62.     char            buf[8192];
  63.     char           *temp;
  64.  
  65.  
  66.     fd = fileno (from_console);
  67.     oldstat = fcntl (fd, F_GETFL, dummy);
  68.     fcntl (fd, F_SETFL, oldstat | O_NDELAY);
  69.     temp = fgets (buf, 8192, from_console);
  70.     while (temp != NULL)
  71.       {
  72.         XmTextInsert (console, XmTextGetLastPosition (console), buf);
  73.         XmTextShowPosition (console, XmTextGetLastPosition (console));
  74.         temp = fgets (buf, 8192, from_console);
  75.       }
  76.     fcntl (fd, F_SETFL, oldstat);
  77. }
  78.  
  79.  
  80. In article <1992Aug12.172834.21325@Veritas.COM>, joe@Veritas.COM (Joe Fasano) writes:
  81. |> Does anyone have a method for redirecting 
  82. |> stdout and stderr to the XmText widget ? 
  83. |> 
  84. |>    Thanks, 
  85. |> 
  86. |>    joe@veritas.com
  87. |> 
  88. |> -- 
  89. |>     -------------------------------------------------------------
  90. |>     joe            ARPAnet:  veritas!joe@apple.com
  91. |>     joe@veritas.com        UUCPnet:  {apple,pyramid}!veritas!joe
  92. -----------------------------------------------------------------------------
  93. Michael G. Reed                                  (reed@Theory.TC.Cornell.edu)
  94. Cornell National Supercomputing Facility                       (607)/254-8806
  95. -----------------------------------------------------------------------------
  96.         Why be normal, it's boring; and boring people should be shot.
  97.  
  98. Note:  These are not the views of my employer (and probably not mine either).
  99.