[GRASS-dev] Merging stdout and stderr
paul-grass at stjohnspoint.co.uk
Mon Nov 13 17:14:20 EST 2006
The GRASS console thing (I guess that's where the name gronsole comes
from?) which runs commands via the Tcl/Tk "open" command and captures
their stdout and stderr, displaying some output as-is to the gronsole
window and catching certain things like percentage complete and warnings
and displaying them differently is actually quite cool.
I remember discussion on the list about how stdout and stderr had to be
merged because Tcl/Tk has a bug/feature in that it treats anything written
to stderr as an error indicator for the called program. On Unix this
merging is done as follows:
set cmd [concat | $cmd 2>@ stdout]
but the "2>@ stdout" syntax will not work on Windows. A cross-platform
solution would be to use the "|&" redirector instead of "2>@". "|&" means
"pipe both stdout and stderr to stdin of the following command" (see
http://www.tcl.tk/man/tcl8.5/tutorial/Tcl26.html ). This command could
then copy everything to its stdout and that's what gronsole gets back.
The Unix cat command is an obvious choice but it isn't available on
Windows. "more" kind of works but it's a shell (cmd.exe) built-in command
on Windows so not suitable either. I was wondering if anybody has any
1. Are there any other Windows commands that might be suitable for this?
2. Might it be a worthwhile idea to include a simple program with GRASS
that did this (copies everything from stdin to stdout) so we can be sure
what's going on?
I know I could get this working some hackish way but would like to do it
as elegantly as possible - so it would be great if we can come up with
More information about the grass-dev