如何分配从 IDE 运行脚本的伪 tty?



Eclipse(以及其他IDE,如Pycharm/IntelliJ(似乎没有使用适当的终端来运行程序。当程序需要使用正确的标准/标准输出时,这可能会导致一些问题。

例如,简单的 python 脚本

# 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 运行时将失败并显示以下错误

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>)的任何调用都将失败。

我想知道是否有任何插件或设置,Eclipse 或 IntelliJ,可以通过在适当的 bash 进程中运行脚本来修复这些错误。

IntelliJ实际上有一个"在其运行配置选项中模拟输出控制台中的终端"复选框,该复选框修复了这些错误,但由于某种原因,它没有注册我的 Enter 键 - 使其或多或少无用

对于IntelliJ IDEA和PyCharm,有一个隐藏的选项,可以通过添加

-Drun.processes.with.pty=true

Help |编辑自定义 VM 选项

有关相关请求,请参阅此处。

最新更新