How to allocate a pseudo-tty in which to run scripts from IDE?

痴心易碎 提交于 2019-12-12 05:25:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!