python3打开程序_python3打开终端并运行程序

我用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,如果这很重要的话。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值