Pydev: send stdout to a real (tty) terminal

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

I came across several examples when the tty terminal restriction was not limited. In the case of the subprocess module, I can use the CREATE_NEW_CONSOLE flag, but in other cases, for example, in this issue ( Print \ r in the console ), the PyDev console does not seem to support the use of escape characters.

Any thoughts are appreciated.

+3
source share
2 answers

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

Aptana Studio , , , , .

, Python, :

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.
0

logging , , , .

, PyDev- . , Helios Windows, Unicode, - .

, , sleep 3600 , :

import sys
def redirect_terminal(ttypath):
  term = open(ttypath, 'w+')
  sys.stdout = term
  sys.stderr = term

, , , PyDev, ( , ):

>>> redirect_terminal('/dev/pts/0')
>>> dir()
>>> raise TypeError
>>>

/dev/pts/0:

['__builtins__', '__doc__', '__name__', '__package__', 'redirect_terminal', 'sys']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError

- , , , .

. , .

+1

All Articles