Broken when piped to.
See original GitHub issueWhen piping to python script that uses prompt()
everything breaks:
File "/home/user/lib/python3.6/site-packages/prompt_toolkit/input.py", line 67, in __init__
assert self.stdin.isatty()
AssertionError
To reproduce:
#test.py
from prompt_toolkit import prompt
text = prompt('> ')
Then:
$ echo "foo" | python test.py
<...>
File "/home/user/lib/python3.6/site-packages/prompt_toolkit/input.py", line 67, in __init__
assert self.stdin.isatty()
AssertionError
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
What causes the Broken Pipe Error? - Stack Overflow
The error condition is detected at some point. With a small write, you are inside the MTU of the system, so the message...
Read more >Broken Pipe Error in Python - GeeksforGeeks
A broken Pipe Error is generally an Input/Output Error, which is occurred at the Linux System level. The error has occurred during the...
Read more >9 Things You Should Do When You Find A Burst Or Broken Pipe
1. Turn off the Water · 2. Cut the Electricity · 3. Remove Valuables From the Room · 4. Call a Professional ·...
Read more >How to fix Broken Pipe Error in Linux - net2
Broken pipe occurs when a process prematurely exits from either end and the other process has not yet closed the pipe. Example use...
Read more >How to Repair a Broken Pipe in Your Home
1. Locate the shutoff valve to your water main and close the valve. 2. The burst pipe could be a number of places...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, a Posix pipe is not the same as a PTY (pseudo terminal). Both are I/O devices, but they have different properties.
Probably there are other differences. There is a lot of non-obvious low level I/O underneath. But in any case, prompt_toolkit won’t support pipes as stdin. Maybe with some hacks it will work partly, but seriously, it’ll take only a few lines of code to read stdin yourself, if the input doesn’t appear to be a tty.
Hi @Granitosaurus,
Thanks for reporting the issue. This is however something which won’t be fixed. (I guess I definitely need to given better error message as feedback.)
The reason is that prompt_toolkit is meant for user interaction, not for machine-interaction like a pipe. If you want to support pipe input on the other hand, it’s best to test for
sys.stdin.isatty()
yourself, and if that is true, then usesys.stdin.read/readline
to retrieve the input.The same is true for piping the output to something else. If you’d pipe stdout to a file, the result will be a meaningless sequence of ANSI escape characters. If
sys.stdout.isatty()
is true, don’t use prompt_toolkit.