I have a C++ program and I want to determine whether the parent process is a terminal or not. Because if it is a terminal, I can use escape codes to highlight the output, else this will be displayed with unreadable characters. The solution need to run on any posix system.
If anyone knows the solution for Java I would be interested in it as well.
If I understand your problem correctly, you're looking at it from the wrong angle. Ask not what your parent process is, but rather what the capabilities of stdout
are. And to do that in a POSIX environment, use isatty()
.
For stdout, isatty(STDOUT_FILENO)
should return 1
.
In Java, System.console()
will apparently return a Console
object if both stdin and stdout are a terminal, and null
otherwise. See How can I check if a Java program's input/output streams are connected to a terminal? for more details.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments