Don't assume stdin is a TTY

Check whether stdin is a TTY before performing TTY operations that would
cause an exception to be raised. Makes sudo usable e.g. when invoking
commands via ssh.
Merge pull request #3 from weinhold/master

Don't assume stdin is a TTY