6

A while ago, I asked how I could determine, from a C++ program running on Windows, whether stdout was pointing to the console. I received a useful answer: GetConsoleMode().

UPDATE: To be specific, this expression evaluates as true if stdout points to the console:

GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &temp)

Now I'm trying to solve the same problem on Mac. Is there a similar function that I can call from Mac OS X to determine whether stdout is pointing to the console?

UPDATE: People have suggested using the function isatty(), which takes a file descriptor. In the Windows case, that descriptor was obtained by calling GetStdHandle(STD_OUTPUT_HANDLE). I will check out whether I can call isatty(fileno(stdout)), as suggested.

Community
  • 1
  • 1
Alan
  • 1,889
  • 2
  • 18
  • 30
  • 4
    Do you know [isatty](http://linux.die.net/man/3/isatty)? That function should be a portable solution to your problem – fvu Jul 27 '15 at 21:19

0 Answers0