diff --git a/cmd/miqt-docker/isatty_linux.go b/cmd/miqt-docker/isatty_linux.go new file mode 100644 index 00000000..920fd9b9 --- /dev/null +++ b/cmd/miqt-docker/isatty_linux.go @@ -0,0 +1,24 @@ +//+build linux +//go:build linux + +package main + +import ( + "os" + "syscall" + "unsafe" +) + +func isatty() bool { + fd := os.Stdout.Fd() + req := syscall.TCGETS + termios := syscall.Termios{} + + _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(unsafe.Pointer(&termios))) + if errno != 0 { + return false + } + + // Successfully got Termios info = stdout is a tty + return true +} diff --git a/cmd/miqt-docker/isatty_other.go b/cmd/miqt-docker/isatty_other.go new file mode 100644 index 00000000..cd73eb93 --- /dev/null +++ b/cmd/miqt-docker/isatty_other.go @@ -0,0 +1,8 @@ +//+build !linux +//go:build !linux + +package main + +func isatty() bool { + return true +} diff --git a/cmd/miqt-docker/main.go b/cmd/miqt-docker/main.go index 87fc5dd8..dd8ffd75 100644 --- a/cmd/miqt-docker/main.go +++ b/cmd/miqt-docker/main.go @@ -115,7 +115,11 @@ func main() { // Container match found - safe to run our command - fullCommand := []string{"run", "-it"} + fullCommand := []string{"run"} + + if isatty() { + fullCommand = append(fullCommand, "-it") + } if runtime.GOOS != "windows" { userinfo, err := user.Current()