home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!ames!uakari.primate.wisc.edu!usenet.coe.montana.edu!rpi!batcomputer!snake.tc.cornell.edu!reed
- From: reed@snake.tc.cornell.edu (Michael G. Reed)
- Newsgroups: comp.windows.x.motif
- Subject: Re: stderr and stdout to XmText widget
- Keywords: stderr stdout XmText
- Message-ID: <1992Aug12.192500.15056@tc.cornell.edu>
- Date: 12 Aug 92 19:25:00 GMT
- References: <1992Aug12.172834.21325@Veritas.COM>
- Sender: news@tc.cornell.edu
- Reply-To: reed@Theory.TC.Cornell.EDU
- Distribution: comp.windows.x.motif
- Organization: Cornell National Supercomputing Facility
- Lines: 83
- Nntp-Posting-Host: snake.tc.cornell.edu
-
-
- Here's some code I used not to long ago. It pipes stderr/stdout from it's
- child processes to a text widget (assumes the text widget is already created
- and called "console", a global), but it's easily modified to do it for the
- current app (as a matter of fact, I think the changes I just did will snag
- the current app). Hope this helps.
-
- -Michael
-
-
-
- int child_pipe[2];
- FILE *from_console;
- FILE *to_console;
- Widget top_level; /* toplevel shell */
- Widget console; /* your text widget */
-
- {
- if (pipe (child_pipe))
- {
- fprintf (stderr, "%s: Could not open child pipe.\n", progname);
- exit (PIPE_ERROR);
- }
- to_console = fdopen (child_pipe[1], "w");
- from_console = fdopen (child_pipe[0], "r");
- XtAppAddInput (XtWidgetToApplicationContext (toplevel), child_pipe[0],
- (XtPointer) XtInputReadMask, output_from_child, NULL);
-
- /* These two lines can apply to your current app, or children...nice for getting
- stderr/stdout from child processes */
-
- if ((n1 = dup2 (child_pipe[1], 1)) == -1)
- fprintf (stderr, "%s: Failed to duplicate to stdout.\n", progname);
- if ((n2 = dup2 (child_pipe[1], 2)) == -1)
- fprintf (stderr, "%s: Failed to duplicate to stderr.\n", progname);
- }
-
-
- void
- output_from_child ()
-
- {
-
- int fd,
- dummy = 0,
- oldstat;
- char buf[8192];
- char *temp;
-
-
- fd = fileno (from_console);
- oldstat = fcntl (fd, F_GETFL, dummy);
- fcntl (fd, F_SETFL, oldstat | O_NDELAY);
- temp = fgets (buf, 8192, from_console);
- while (temp != NULL)
- {
- XmTextInsert (console, XmTextGetLastPosition (console), buf);
- XmTextShowPosition (console, XmTextGetLastPosition (console));
- temp = fgets (buf, 8192, from_console);
- }
- fcntl (fd, F_SETFL, oldstat);
- }
-
-
- In article <1992Aug12.172834.21325@Veritas.COM>, joe@Veritas.COM (Joe Fasano) writes:
- |> Does anyone have a method for redirecting
- |> stdout and stderr to the XmText widget ?
- |>
- |> Thanks,
- |>
- |> joe@veritas.com
- |>
- |> --
- |> -------------------------------------------------------------
- |> joe ARPAnet: veritas!joe@apple.com
- |> joe@veritas.com UUCPnet: {apple,pyramid}!veritas!joe
- -----------------------------------------------------------------------------
- Michael G. Reed (reed@Theory.TC.Cornell.edu)
- Cornell National Supercomputing Facility (607)/254-8806
- -----------------------------------------------------------------------------
- Why be normal, it's boring; and boring people should be shot.
-
- Note: These are not the views of my employer (and probably not mine either).
-