client: function to check if stdin is a tty
[hcoop/domtool2.git] / src / client.sml
index 00000e7..a92b13f 100644 (file)
@@ -25,12 +25,15 @@ datatype passwd_result =
        | Aborted
        | Error
 
+fun hastty () =
+    Posix.ProcEnv.isatty Posix.FileSys.stdin
+
 fun getpass () =
     let
        val tty = Posix.FileSys.stdin
        val termios = SOME (Posix.TTY.TC.getattr tty)
                      handle OS.SysErr (reason, SOME syserr) =>
-                            if syserr = Posix.Error.notty then
+                            if syserr = Posix.Error.notty orelse syserr = Posix.Error.inval then
                                 (print "Warning: no terminal found, not hiding password\n";
                                  TextIO.flushOut TextIO.stdOut;
                                  NONE)