Forums

Writing to stderr

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Writing to stderr

Postby Caligari » Mon Jul 06, 2009 9:56 pm

I understand that I can point print to a different writer, but I don't know what writer to use in order to get my output to appear on stderr.

I'm sure it is something obvious, but I don't know .NET well enough to be able to work out what to do at that end, and I can't immediately see anything in Cobra itself which gives me a stderr stream.
Caligari
 
Posts: 33

Re: Writing to stderr

Postby Charles » Mon Jul 06, 2009 11:02 pm

On .NET, Console.error is a reference to stderr. It's type is TextWriter.

You can use the print statement on it like so:
# simple case:
err = Console.error to !
print to err, 'x = [x]'

# redirect
print to err
print "error:"
obj.foo
obj.bar

Or you can use methods on it like: Console.error.writeLine('x = [x]')

I don't know under what circumstance Console.error may be nil/null. It's up to you if you want to check for that.

See also: http://msdn.microsoft.com/en-us/library/system.console.error.aspx
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 48 guests