Pydev: Send Stdout To A Real (tty) Terminal
Solution 1:
I normally deal with issues like this through the logging
module in the standard library, which is quite good, but I'll assume you have good reason for wanting this.
I would be surprised if the PyDev console supported full terminal emulation. At least under Helios on Windows, I've had no problem with Unicode display, but terminal escapes are another matter.
If you know specifically which terminal you want to use, you can run sleep 3600
in it and then do this in your test driver:
import sys
defredirect_terminal(ttypath):
term = open(ttypath, 'w+')
sys.stdout = term
sys.stderr = term
Trying this in the interactive interpreter, which will likely be a bit different from running it in PyDev, I get this in the initial terminal (note local echo and prompt still returned here):
>>>redirect_terminal('/dev/pts/0')>>>dir()>>>raise TypeError>>>
and this in the /dev/pts/0
terminal:
['__builtins__', '__doc__', '__name__', '__package__', 'redirect_terminal', 'sys']
Traceback (most recent calllast):
File "<stdin>", line 1, in<module>
TypeError
While I did not try any terminal escapes here, they are just byte sequences that get printed like any other, so they should be printed on the remote terminal.
I cannot manage to collect input from a different terminal in the interactive interpreter. When I try, input is still read from the initial terminal.
Solution 2:
This is currently a limitation in Eclipse... (which PyDev inherits).
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.
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()
ifhasattr(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.
Post a Comment for "Pydev: Send Stdout To A Real (tty) Terminal"