如何从Sublime Text 3中的cmd中运行lua文件? [英] How to run a lua file in cmd from Sublime Text 3?
问题描述
我想在cmd中运行lua文件(出于某种原因,我无法使用构建系统).
我该怎么办?
I want to run lua files in cmd (for a reason I can't use build system).
How can I do this?
推荐答案
由于您只想调用cmd命令,因此可以轻松编写自己的插件.
只需打开您的用户目录并创建一个python文件(例如run_lua.py
).
或仅使用工具" >>新插件".
此插件运行命令lua $file
,然后暂停直到用户按下键:
Since you just want to call a cmd command you can easily write your own plugin.
Just open your user directory and create a python file (e.g. run_lua.py
).
Or just go with Tools >> New Plugin.
This plugin runs the command lua $file
and afterwards pauses until the user pressed a key:
import subprocess
import sublime_plugin
class RunLuaCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
subprocess.Popen(["cmd", "/c", "lua", view.file_name(), "&", "pause"])
添加键绑定:
{
"keys": ["alt+b"],
"command": "run_lua",
},
更一般的方法:
import subprocess
import shlex
import sublime
import sublime_plugin
class RunCmdCommand(sublime_plugin.WindowCommand):
def run(self, command):
variables = self.window.extract_variables()
command_expanded = sublime.expand_variables(command, variables)
# run in cmd
command_arr = ["cmd", "/c"]
# run the command
command_arr.extend(shlex.split(command_expanded, posix=False))
# afterwards wait for a key
command_arr.extend(["&", "pause"])
# execute the command
subprocess.Popen(command_arr)
具有键绑定:
{
"keys": ["alt+b"],
"command": "run_cmd",
"args": {
"command": "lua $file"
}
},
PS.您也可以使用cmd /k
代替cmd /c
,并在最后省略& pause
来创建cmd,该cmd在执行命令后将保持打开状态.暂停时,它将等待按键并关闭.
感谢@EgorSkriptunoff的提示.
PS. You can also use cmd /k
instead of cmd /c
and omit the & pause
at the end to create a cmd, which will stay open after executing the command. With pause it will wait for a keypress and close.
Thanks to @EgorSkriptunoff for the hint.
这篇关于如何从Sublime Text 3中的cmd中运行lua文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!