我有一个python脚本在emacs中为我打开文件,为此它调用xterm中的一个进程,如下所示
"""AutoEmacs Document"""
# imports
import sys
import os
import psutil
import subprocess
from argparse import ArgumentParser
# constants
xlaunch_config = "C:\\cygwin64\\home\\nalis\\Documents\\experiments\\emacs\\Autoemacs\\config.xlaunch"
script = "xterm -display :0 -e emacs-w32 --visit {0}"
# exception classes
# interface functions
# classes
# internal functions & classes
def xlaunch_check():
# checks if an instance of Xlaunch is running
xlaunch_state = []
for p in psutil.process_iter(): #list all running process
try:
if p.name() == 'xlaunch.exe':# once xlaunch is found make an object
xlaunch_state.append(p)
except psutil.Error: # if xlaunch is not found return false
return False
return xlaunch_state != [] #double checks that xlaunch is running
def xlaunch_run(run):
if run == False:
os.startfile(xlaunch_config)
return 0 #Launched
else:
return 1 #Already Running
def emacs_run(f):
subprocess.Popen(script.format(f))
return 0#Launched Sucessfully
def sysarg():
f = sys.argv[1]
il = f.split()
l = il[0].split('\\')
return l[(len(l) - 1)]
def main():
f = sysarg()
xlaunch_running = xlaunch_check()
xlaunch_run(xlaunch_running)
emacs_run(f)
return 0
if __name__ == '__main__':
status = main()
sys.exit(status)
`
它可以很好地处理偶尔出现的错误,但是我想让python发送Xterm控制台,它在启动后根据接收到的输入发送命令,比如“-e emacs-w32”。我已经试过这样的方法了:
^{pr2}$但这似乎没什么用。除了发射终端。我对这件事做了一些研究,但它只使我感到困惑。如能提供帮助,我将不胜感激。在
要在terminal emulator中打开emacs,请使用以下命令:
Linux系统
窗口:
^{pr2}$cygwin使用:
相关问题 更多 >
编程相关推荐