如何分配一个伪tty,以便在IDE中运行脚本? [英] How to allocate a pseudo-tty in which to run scripts from IDE?
问题描述
Eclipse(和其他IDE,例如Pycharm / IntelliJ)似乎没有使用适当的终端来运行程序。当程序需要使用适当的stdin / stdout进行工作时,这可能会导致一些问题。
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.
例如,简单的python脚本
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
直接从bash中运行时可以完美运行,但从任何IDE中运行时都将失败,并出现以下错误
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')
更普遍的是,任何对 tcgetattr(< stdin>)
的调用都会失败。
More generally, any calls to tcgetattr(<stdin>)
will fail.
想知道是否有任何插件或设置(Eclipse或IntelliJ)可以通过在适当的bash进程中运行脚本来修复这些错误。
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实际上在其运行配置选项中具有一个在输出控制台中模拟终端复选框,可修复这些错误,但由于某些原因,它没有注册我的Enter键-使它或多或少变得无用
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
推荐答案
对于IntelliJ IDEA和PyCharm,可以通过添加启用隐藏选项p>
For IntelliJ IDEA and PyCharm there is a hidden option that can be enabled by adding
-Drun.processes.with.pty=true
帮助
中的
| 编辑自定义VM选项。
这篇关于如何分配一个伪tty,以便在IDE中运行脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!