Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Writing to STDERR

369 views
Skip to first unread message

Ian Barton

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

I am trying to create a console App in D3 that needs to write to
STDERR. Does anyone have any ideas how to do this? I can write to
STDOUT by doing AssingFile and passing '' as the file name, but can't
see how to write to STDERR.

iba...@nospamossystems.co.uk
To reply, please remove nospam from the above address.
Web: http://www.ossystems.co.uk

Peter N Roth

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

Ian Barton wrote in message <34fb3959...@forums.borland.com>...

>I am trying to create a console App in D3 that needs to write to
>STDERR. Does anyone have any ideas how to do this?
[ ]

Ian -- I've forgotten how these files are supposed to work...
It used to be, in Pascal, that 'output' was the text that went
to the output file identified by the overridden parameter
on the command line. (Too arcane to go into now)

There was no 'stderr', unless it was
provided by the OS. I presume stderr is the file
on your system that you want stuff to appear in
on the screen?

I'm sure there'll be other suggestions; how about
writing all the stderr stuff to a TStringList. Instead of using
writeln, use TS.Add(s). Display it in a Listbox.

Hope this doesn't sound like Taelon.

--
Grace + Peace | Peter N Roth | Engineering Objects Int'l
Now shipping version 4 of ClassBuilder++
Visit our website at http://www.inconresearch.com/eoi
"Random numbers are too important to be left to chance." - anon


Dave Laumann

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

>I am trying to create a console App in D3 that needs to write to
>STDERR. Does anyone have any ideas how to do this? I can write to
>STDOUT by doing AssingFile and passing '' as the file name, but can't
>see how to write to STDERR.


see the api functions getstdhandle() <- which returns either a handle for
stdin, stdout, or stderr.
and setstdhandle() which allows you to redirect the handle associated with
stdin, stdout, and stderr (then subsequent calls to getstdhandle() will
return the appropriate handle)

-dave
djl@tiptec@h.com
remove the second @

Peter Below

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Ian,

the Win32 API has a function get the standard file handles:

hStderr := GetStdHandle( STD_ERROR_HANDLE );

Getting a Delphi Textfile variable to use this handle requires a bit of
unpleasant digging into the entrails of the file variables. You can do it
this way:


Var
stderr: Textfile;

Begin
WriteLn;
// essential to write something to stdout, otherwise output will
// not be open!
Move( output, stderr, Sizeof( stderr ));
TTextRec( stderr ).Handle := GetStdhandle( STD_ERROR_HANDLE );

WriteLn( stderr, 'Bad, bad app!' );

There is no need to close this handle, as far as i'm aware.

Peter Below (TeamB) 10011...@compuserve.com)


Peter N Roth

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Peter Below <10011...@compuserve.com> wrote in message ...

Still... I keep learning!

What would be a reason to use these std files?

Peter Below

unread,
Mar 4, 1998, 3:00:00 AM3/4/98
to

In article <6dibmp$jd...@forums.borland.com>, Peter N Roth wrote:
> What would be a reason to use these std files?
>
Both stdout and stderr output to the screen but they are handled
differently in redirection. If the output of an console or DOS app is
redirected to a file, for example, this will only affect stdout. Messages
to stderr will still appear on screen.

Peter Below (TeamB) 10011...@compuserve.com)


Dave Laumann

unread,
Mar 5, 1998, 3:00:00 AM3/5/98
to

>> What would be a reason to use these std files?
>>
>Both stdout and stderr output to the screen but they are handled
>differently in redirection. If the output of an console or DOS app is
>redirected to a file, for example, this will only affect stdout. Messages
>to stderr will still appear on screen.


yes, and (at least in a unix environment) the buffer for stderr was
guaranteed to output to your tty (screen) (ie it was like implicitly calling
flush after every write). so, if your program terminated abnormally, you
would see _all_ data that you wrote to stderr, but not necessarily all data
written to stdout... you might even have code that wrote to stdout first
then some code that wrote to stderr later and you might see the stderr
output first.

--

Ian Barton

unread,
Mar 6, 1998, 3:00:00 AM3/6/98
to

On Mon, 2 Mar 1998 20:34:58 -0500, "Peter N Roth" <pete*ro...@erols.com
(remove * to email me)> wrote:

>There was no 'stderr', unless it was
>provided by the OS. I presume stderr is the file
>on your system that you want stuff to appear in
>on the screen?
>

Peter,

I have managed to do this by using GetStdHandle
MyHandle := GetStdHandle(STD_ERROR_HANDLE);
WriteFile(MyHandle, PChar(MyStr)^, StrLen(PChar(MyStr)),
lngBytesWritten, nil);

Ian Barton

unread,
Mar 6, 1998, 3:00:00 AM3/6/98
to

On Tue, 3 Mar 1998 20:53:35 -0500, "Peter N Roth" <pete*ro...@erols.com

(remove * to email me)> wrote:

>Peter Below <10011...@compuserve.com> wrote in message ...
>
>Still... I keep learning!
>

>What would be a reason to use these std files?

My reason is that I am writing an autoresponder program for our mail
server. The mail server software provides a way of writing data such
as mail headers via STDERR and STDOUT.


Peter N Roth

unread,
Mar 6, 1998, 3:00:00 AM3/6/98
to

Ian Barton wrote in message <34ffb155...@forums.borland.com>...


All the best... I am continually amazed at the ingenuity
I see displayed in these ngs.

0 new messages