 <p>Python:</p> <pre><code>import os import sys if os.isatty(sys.stdin.fileno()): print "is a tty" else: print "not a tty" </code></pre> <p>I'm not aware of a Java equivalent using the default libraries; Jython appears to use native code (<a href="http://kenai.com/projects/jna-posix" rel="nofollow noreferrer">jna-posix</a>).</p> <p><strong>Update -</strong> here's two possibilities:</p> <ul> <li><a href="http://download.oracle.com/javase/6/docs/api/java/lang/System.html#console()" rel="nofollow noreferrer">System.console()</a> returns a console object if there is one; <code>null</code> otherwise (see <a href="http://stackoverflow.com/questions/4005378/console-writeline-and-system-out-println">here</a> and <a href="http://stackoverflow.com/questions/2369731/java-console-applications-is-system-out-still-the-way-to-go">here</a>)</li> <li>System.out.<a href="http://download.oracle.com/javase/6/docs/api/java/io/InputStream.html#available()" rel="nofollow noreferrer">available()</a> returns 0 if there's no input immediately available, which tends to mean stdin is a terminal (but not always - this is a less accurate test)</li> </ul>