问题
Eclipse (and other IDEs, such as Pycharm/IntelliJ), don't seem to use a proper terminal with which to run programs. This can lead to some problems when a program needs to work with a proper stdin/stdout.
For example, the simple python script
# Exit upon any keypress
import sys
import termios
import tty
fd = sys.stdin.fileno()
tty.setraw(sys.stdin.fileno())
while not sys.stdin.read(1):
pass
Will function perfectly when run directly from bash, but will fail with the following error when from from any IDE
Traceback (most recent call last):
File "/Users/anishmoorthy/Code/termserver/turst.py", line 19, in <module>
while readchar() is None:
File "/Users/anishmoorthy/Code/termserver/turst.py", line 10, in readchar
tty.setraw(sys.stdin.fileno())
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tty.py", line 20, in setraw
mode = tcgetattr(fd)
termios.error: (25, 'Inappropriate ioctl for device')
More generally, any calls to tcgetattr(<stdin>) will fail.
I was wondering if there were any plugins or settings, Eclipse or IntelliJ, which would fix these errors by running scripts in a proper bash process.
IntelliJ actually has an ."Emulate terminal in output console" checkbox in its run configuration options which fixes these errors, but for some reason it doesn't register my enter key- making it more or less useless
回答1:
For IntelliJ IDEA and PyCharm there is a hidden option that can be enabled by adding
-Drun.processes.with.pty=true
in Help | Edit Custom VM Options.
See here for the related request.
来源:https://stackoverflow.com/questions/44851652/how-to-allocate-a-pseudo-tty-in-which-to-run-scripts-from-ide