cram icon indicating copy to clipboard operation
cram copied to clipboard

Differentiate between stdout and stderr

Open esc opened this issue 9 years ago • 2 comments

Is is possible to differentiate between stdout and stderr? For example to check that an error message was printed to stderr instead of stdout?

cc @snordhausen

esc avatar Feb 15 '16 10:02 esc

You could redirect the two streams to separate files and cat them/check the output separately. Would that work for what you're trying to do?

E.g:

  $ command 2> stderr.log > stdout.log
  $ cat stderr.log
  Error message!
  $ cat stdout.log
  Regular output!

I'm trying to think of how this could be supported directly in the test syntax, but I'm not sure if it's possible. Right now when Cram invokes the shell, it redirects stderr to stdout. This makes it possible for the two output streams to be properly mixed together and checked in the tests. If Cram didn't do that redirection, I'm not sure it'd be possible to interleave the two output streams properly after the fact.

aiiie avatar Feb 24 '16 11:02 aiiie

Maybe an alternative syntax could be used, with a special symbol, e.g. |:

  $ command
  Regular output!
  |Error message!

I am guessing here, but the separation and redirection could work, although it is somewhat cumbersome.

esc avatar Feb 24 '16 11:02 esc