Pydev:发送stdout到一个真实的(tty)终端 [英] Pydev: Send stdout to a real (tty) terminal

查看:198
本文介绍了Pydev:发送stdout到一个真实的(tty)终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续上一个问题(子流程:PyDev控制台与cmd.exe ),有没有办法改变PyDev发送stdout的位置 - 即到tty终端?

Following up on a previous question ( subprocess: PyDev console vs. cmd.exe ), is there a way to change where PyDev sends stdout--namely to a tty terminal?

我遇到了几个没有tty终端已经受到限制。对于子进程模块的情况,我可以使用CREATE_NEW_CONSOLE标志,但在其他情况下,例如在此问题(在控制台中正确打印\r ),PyDev控制台似乎不支持使用转义字符。

I've come across several instances where not having a tty terminal has been limiting. For the case of the subprocess module, I can use the CREATE_NEW_CONSOLE flag, but in other instances, such as in this question ( Print \r correctly in console ), the PyDev console doesn't seem to support using escape characters.

任何想法。

推荐答案

这是目前Eclipse ...(PyDev继承的)的限制。

This is currently a limitation in Eclipse... (which PyDev inherits).

Aptana Studio有一个终端视图,可能用于替换,但目前没有计划这样做。

Aptana Studio does have a terminal view which could probably be used as a replacement, but there are no plans to do so for now.

回答评论下面,从运行的Python程序创建一个新的shell可以使用下面的代码:

Answering comment below, to create a new shell from a running Python program it's possible to use the code below:

import subprocess
import sys
import os
args = [sys.executable] + sys.argv
new_environ = os.environ.copy()

if hasattr(subprocess, 'CREATE_NEW_CONSOLE'):
    popen = subprocess.Popen(args, env=new_environ, creationflags=subprocess.CREATE_NEW_CONSOLE)
    exit_code = popen.wait()
else:
    #On Linux, CREATE_NEW_CONSOLE is not available, thus, we use xterm itself.
    args = ['xterm', '-e'] + args
    popen = subprocess.Popen(args, env=new_environ)
    popen.wait() #This exit code will always be 0 when xterm is executed.

这篇关于Pydev:发送stdout到一个真实的(tty)终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆