I'm interfacing with a standalone executable, and all is well except that debugEcho is stdout, so if I want to get debug info from that program, it gets merged with process.readLine().
Is there a way to make debugEcho output to stderr, or do I have to create my own errorEcho to output to stderr? Bu that will not be noSideEffects....
Also will process.hasData be true as long as there is either stdout or stderr ? If so, is there a way to differentiate ? In other words, how will I know which stream to read, either stdout or stderr, since readLine() waits until there is data available, so may block the program if not handled well.
you can create your own debugEcho that writes to stderr lying to the compiler and telling it has no side effects:
proc debugEchoStderr*(x: varargs[string, `$`]) =
{. cast(noSideEffect) .}:
stderr.writeLine x
func add(a, b: int): int =
debugEchoStderr a + b
return a + b
let c = add(1, 2) # outputs 3
Was about to post basically the same thing.
One thing I'll note is that you can use {.noSideEffect.}: instead of {. cast(noSideEffect) .}:.
Thank you both.
To make this complete: hasData only applies to stdout. So getting standard error needs to be with a try, peek might be possible, but a simple try works...