現在の行のテキストを読み取り、それをシェル コマンドとして実行し、コマンドの出力をエディターに配置する Sublime 用のプラグインを作成しようとしています。これは私がこれまでに持っているものです:
import sublime, sublime_plugin, os, os.path
import subprocess
def GetLineAtCursor(view):
pos = view.sel()[0].a
reg = view.line(pos)
return view.substr(reg)
class ExecuteLineGetOutputCommand(sublime_plugin.TextCommand):
def run(self, edit):
line = GetLineAtCursor(self.view).strip().split()
output = subprocess.check_output(line,shell=True)
self.view.insert(edit, 0, output)
これは機能していません。具体的にはsubprocess.check_output(...)
、python インタープリターでは問題なく動作しますが、への呼び出しが機能しません。次のように、try ブロックに入れます。
try:
output = subprocess.check_output(line,shell=True)
except Exception as e:
self.view.insert(edit, 0, str(e))
どのコマンドを試しても、次の出力が生成されます。
[WinError 6] The handle is invalid
問題が何であるか、そしてそれを修正する方法を知っている人はいますか?