Skip to content
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

"panic: inappropriate ioctl for device" when stdin is reused #88

Closed
bcicen opened this issue Aug 12, 2018 · 1 comment · Fixed by #89
Closed

"panic: inappropriate ioctl for device" when stdin is reused #88

bcicen opened this issue Aug 12, 2018 · 1 comment · Fixed by #89

Comments

@bcicen
Copy link
Contributor

bcicen commented Aug 12, 2018

Bug reports

When a program reads input from stdin (i.e, piped in before initializing the prompt), go-prompt attempts to reuse this same pipe to read user input interactively, resulting in a panic:

panic: inappropriate ioctl for device

goroutine 1 [running]:
github.com/c-bata/go-prompt.(*PosixParser).GetWinSize(0xc420102b90, 0x871ee0)
	/home/bradley/go/src/github.com/c-bata/go-prompt/input_posix.go:113 +0xdd

Expected Behavior

go-prompt should always open a fresh stdin descriptor when initialized

Current Behavior and Steps to Reproduce

Read from stdin before starting the prompt

Context

  • Operating System: Linux
  • Terminal Emulator: Terminator
  • tag of go-prompt or commit revision: aa7dc8b
@bcicen bcicen changed the title panic: inappropriate ioctl for device when stdin is reused "panic: inappropriate ioctl for device" when stdin is reused Aug 12, 2018
@c-bata
Copy link
Owner

c-bata commented Aug 26, 2018

Thanks you. 👍

abrander added a commit to abrander/go-prompt that referenced this issue Aug 14, 2020
When using go-prompt before /dev/ is populated, it will panic() from
NewStandardInputParser() because /dev/ isn't populated yet.

This will use stdin (fd 0) as a fallback if /dev/tty doesn't exist.

Furthermore GetWinSize() will return the default console size if the
IOCTL call fails. This can happen if the default stdin is not a
terminal, but a pipe as fixed in commit 846777c and described in
issue c-bata#88.
rbergman pushed a commit to rbergman/go-prompt that referenced this issue Jun 3, 2021
When using go-prompt before /dev/ is populated, it will panic() from
NewStandardInputParser() because /dev/ isn't populated yet.

This will use stdin (fd 0) as a fallback if /dev/tty doesn't exist.

Furthermore GetWinSize() will return the default console size if the
IOCTL call fails. This can happen if the default stdin is not a
terminal, but a pipe as fixed in commit 846777c and described in
issue c-bata#88.

(cherry picked from commit aba8e36)
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

Successfully merging a pull request may close this issue.

2 participants