如何从 Sublime Text 3 在 cmd 中 运行 一个 lua 文件?
How to run a lua file in cmd from Sublime Text 3?
我想在 cmd 中 运行 lua 文件(由于我无法使用构建系统的原因)。
我该怎么做?
根据插件的特性,我认为您无法做到这一点:
Opens a terminal in the folder containing the currently edited file
Opens a terminal in the project folder containing the currently edited
file
该插件只会打开您的 project/file 目录的终端。
我认为文档突出显示的参数是关于配置您的终端而不是 运行 任何类型的命令。
该插件无论如何都能让您的生活更轻松。您可以在您的工作目录中打开您的命令 prompt/terminal,然后只需 运行 您需要的命令。之后,您可以使用命令提示符的历史记录(Arrow Up 或 Arrow Down)导航到您之前的命令。
既然你只想调用一个 cmd 命令,你可以很容易地编写你自己的插件。
只需打开您的用户目录并创建一个 python 文件(例如 run_lua.py
)。
或者直接使用工具 >> 新插件。
这个插件运行命令 lua $file
然后暂停直到用户按下一个键:
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,该命令将在执行命令后保持打开状态。暂停后,它将等待按键并关闭。
感谢@EgorSkriptunoff 的提示。
你可以考虑使用 sublimeREPL 插件。它以新 "code tab" 的形式打开命令提示符。我需要将我的 lua 安装添加到我的路径中。它打开一个交互式 shell 并支持多种 shell 包括 Lua.
我想在 cmd 中 运行 lua 文件(由于我无法使用构建系统的原因)。
我该怎么做?
根据插件的特性,我认为您无法做到这一点:
Opens a terminal in the folder containing the currently edited file
Opens a terminal in the project folder containing the currently edited file
该插件只会打开您的 project/file 目录的终端。
我认为文档突出显示的参数是关于配置您的终端而不是 运行 任何类型的命令。
该插件无论如何都能让您的生活更轻松。您可以在您的工作目录中打开您的命令 prompt/terminal,然后只需 运行 您需要的命令。之后,您可以使用命令提示符的历史记录(Arrow Up 或 Arrow Down)导航到您之前的命令。
既然你只想调用一个 cmd 命令,你可以很容易地编写你自己的插件。
只需打开您的用户目录并创建一个 python 文件(例如 run_lua.py
)。
或者直接使用工具 >> 新插件。
这个插件运行命令 lua $file
然后暂停直到用户按下一个键:
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,该命令将在执行命令后保持打开状态。暂停后,它将等待按键并关闭。
感谢@EgorSkriptunoff 的提示。
你可以考虑使用 sublimeREPL 插件。它以新 "code tab" 的形式打开命令提示符。我需要将我的 lua 安装添加到我的路径中。它打开一个交互式 shell 并支持多种 shell 包括 Lua.