10

I need my program to behave differently, depending on whether the output is to a terminal or to a file. How can I find this out from within C++?

I assume there is no solution that works for all operating systems. For my purposes, it would be good to have one strategy which works under Windows and one which works under linux/unix.

Thanks in advance.

Egon
  • 317
  • 1
  • 3
  • 9

1 Answers1

4

This will help under linux: How to tell if running in a linux console versus an ssh session?

Yes it is a C call, but it can definitely be called from C++.

GetStdHandle gives a similar starting point under windows:

Community
  • 1
  • 1
Danny Staple
  • 7,101
  • 4
  • 43
  • 56