How to write to stderr in Nim?
Asked Answered
P

2

11

I know there is echo, which writes to stdout. Is it possible to redirect echo to stderr, or is there another way to write to stderr?

Protist answered 23/10, 2017 at 20:27 Comment(0)
P
14

It is not possible to redirect echo, but the same can be achieved by using writeLine on the stderr handle (no special imports required):

stderr.writeLine("Error: ", 42)

Documentation links:

Protist answered 23/10, 2017 at 20:27 Comment(0)
P
0

Another way is to call writeLine. It is listed among the system Exports. The docs for echo suggest also calling flushFile as below.

writeLine(stderr, "my err")
flushFile(stderr)

This was tested with Nim 1.4.2.

Powder answered 20/12, 2020 at 3:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.