Skip to content

sample code runs into error: operation not supported by device #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kcmvp opened this issue Jan 13, 2024 · 4 comments
Closed

sample code runs into error: operation not supported by device #185

kcmvp opened this issue Jan 13, 2024 · 4 comments

Comments

@kcmvp
Copy link

kcmvp commented Jan 13, 2024

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 kcmvp changed the title sample code runs into error sample code runs into error: operation not supported by device Jan 13, 2024
@kcmvp
Copy link
Author

kcmvp commented Jan 13, 2024

seems it's issue from term, I have raised a bug here
golang/go#65095

@creack
Copy link
Owner

creack commented Jan 13, 2024

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

@aixintai
Copy link

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

@creack
Copy link
Owner

creack commented Mar 21, 2024

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 creack closed this as completed Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants