我用sublime编写了一个小脚本,它将从用户计算机上的json文件中提取命令,然后打开终端并运行settings/command。这是可行的,只是它不能真正打开终端。它只运行命令(在我的例子中,它将运行gcc来编译一个简单的C文件),并且在不打开终端的情况下管道到STDOUT。在import json
import subprocess
import sublime_plugin
class CompilerCommand(sublime_plugin.TextCommand):
def get_dir(self, fullpath):
path = fullpath.split("\\")
path.pop()
path = "\\".join(path)
return path
def get_settings(self, path):
_settings_path = path + "\\compiler_settings.json"
return json.loads(open(_settings_path).read())
def run(self, edit):
_path = self.get_dir(self.view.file_name())
_settings = self.get_settings(_path)
_driver = _path.split("\\")[0]
_command = _driver + " && cd " + _path + " && " + _settings["compile"] + " && " + _settings["exec"]
proc = subprocess.Popen(_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
我不确定使用subprocess.Popen是否是正确的方法,因为我是Python新手。在
所以要重新迭代;我希望它打开终端,运行命令,并让终端保持打开状态,直到用户按ENTER键或其他东西。我在运行Windows7和Python3,如果这很重要的话。在