pty icon indicating copy to clipboard operation
pty copied to clipboard

sample code runs into error: operation not supported by device

Open kcmvp opened this issue 1 year ago • 2 comments

here is the sample code from document

`// Set stdin in raw mode. oldState, err := term.MakeRaw(int(os.Stdin.Fd())) if err != nil { panic(err) } defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.

// Copy stdin to the pty and the pty to stdout.
// NOTE: The goroutine will keep reading until the next keystroke before returning.
go func() { _, _ = io.Copy(ptmx, os.Stdin) }()
_, _ = io.Copy(os.Stdout, ptmx)

`

The bold line runs into error, the error mesage is operation not supported by device

here is the environment

mac os : 14.2.1 go version: 1.21.4 golang.org/x/term v0.16.0

kcmvp avatar Jan 13 '24 14:01 kcmvp

seems it's issue from term, I have raised a bug here https://github.com/golang/go/issues/65095

kcmvp avatar Jan 13 '24 14:01 kcmvp

I couldn't reproduce on osx 14.2.1 with go 1.21.4. Could you provide a more concrete example by any chance?

creack avatar Jan 13 '24 14:01 creack

the reason the test doesn’t wait for the interactive input is the Stdin of the process that’s executed (test binary), is set to the operating system’s null input device (/dev/null on Unix and NUL on Windows). The DevNull device cannot set the raw mode or resize

aixintai avatar Mar 21 '24 03:03 aixintai

That makes sense, but then there isn't much we can do, the library requires a valid tty device to work.

Closing for now, feel free to re-open if I missed something.

creack avatar Mar 21 '24 03:03 creack