在 VTE 中,您使用 terminal.feed("string")
见vte_terminal_feed。
使用 python Popen 是执行命令的建议方法。如果您想使用命令,那么您应该这样做。
#Uncomment the next line to get the print() function of python 3
#from __future__ import print_function
import os
import subprocess
from subprocess import Popen
command = "echo \"something\""
env = os.environ.copy()
try:
po = Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
universal_newlines=True, env=env)
po.wait()
output, error_output = po.communicate()
if po.returncode:
print(error_output)
else:
print(output)
except OSError as e:
print('Execution failed:', e, file=sys.stderr)
如果您想将 gtk 与 gtk vte 一起使用,请改为执行此操作。
#place the following in a method of a vte instance
env = os.environ.copy()
try:
po = Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
universal_newlines=True, env=env)
po.wait()
output, error_output = po.communicate()
if po.returncode:
print(error_output)
else:
self.feed(output) #here you're printing to your terminal.
except OSError as e:
print('Execution failed:', e, file=sys.stderr)
为了在常规终端中进行最佳控制,您可以尝试cmd 模块。这将要求您生成自己的提示,因此它是获得所需内容的更具体的选项。