C++ stdio redirection
1 messages in this thread
> #: 29671 S5/C Programming
> 26-Oct-92 22:43:13
> Sb: #29517-C++ question
> Fm: Greg Comeau@Comeau Cmptg 72331,3421
> To: Thomas A. Elam 72607,654 (X)
>
> >If you could show me your relevant code, it would help. I'd be willing
> >to look into this problem a bit, as my time allows. I'd like to see it
> >worked out.
>
> It's been quite some time since we looked at this problem but as I recall
> it, it was as simple as this. Given 'blah.c':
>
> #include <stdio.h>
> main() { fprintf(stderr, "abc\n"); }
>
> compiled to 'blah', and given say 'rb.rexx':
>
> blah
> blah
>
> then 'rb.rexx' needs to capture the two "abc\n" somehow.
Here is an ARexx script that demonstrates one method of capturing either
or both standard output and standard error output.
-Tom
—————————– CUT HERE ———————————
/* withlog.rexx */
/* This example ARexx macro program demonstrates a way to redirect both
standard output (stdout) and standard error output (stderr). It works
pretty well, but unfortunately it produces output that looks a little
different from the output of como.rexx from the Comeau C++ 3.0
distribution. (withlog.rexx always echoes the commands it issues,
as is done by como.rexx when it is invoked with its "-V" option.)
By adding option arguments and changing some logic, either or both
standard output and standard error output could be captured, and if
both captured, could be captured either together or separately.
This macro program requires Matt Dillon's freely redistributable FIFO:
device handler (fifo-handler, for the L: directory) and fifo.library
(for the LIBS: directory) from Matt Dillon's distribution. The latest
version of the distribution is fifo374.lzh in the amiga.listings
section on BIX. To start
the handler, there should be no FIFO: entry in the MountList system
file, and the handler should be run in a manner similar to:
run <nil: >nil: L:fifo-handler
*/
arg log
if (log = '') then do
say 'This example macro program requires the name of a log file as an argument.'
exit 1
end
address command
/* Start a new shell. */
'newshell >nil: FIFO:logrexx/rwkecs'
/* Tap the pseudo-console and copy it to the log file. */
'run copy FIFO:logrexx/mrt 'log
MINUSN = 1
/* Make the new shell's prompt null. (This is optional.) */
call doit '', 'prompt "*"*"" > FIFO:logrexx/wm'
call doit 'Test new "doit" with AmigaDOS command', 'list log2 log4'
call doit 'Test new "doit" with output redirection', 'list log2 log4 >t:stdout'
/* Terminate the new shell. */
'echo endcli >FIFO:logrexx/wm'
/* Add a carriage return and line feed to the log file. */
'echo " " >>'log
exit 0
doit:
parse arg saywhat, thecommand
if MINUSN = 1 & saywhat ~= '' then say saywhat
if MINUSV = 1 then say thecommand
if MINUSN = 1 then
'echo >FIFO:logrexx/mw' thecommand
else rc = 0
/* This is to prevent a command from being typed ahead of the appearance */
/* of the prompt. Yuck! */
'wait 1 >nil:'
return rc