简体   繁体   English

构建系统 - Sublime Text 3

[英]Build System - Sublime Text 3

I have the following script called "build-bat.sublime-build":我有以下名为“build-bat.sublime-build”的脚本:

{
  "cmd": "build.bat",
  "working_dir": "$project_path",
  "windows" : {
      "shell": true
  }
}

The script is in C:\\Users\\MyName\\AppData\\Roaming\\Sublime Text 3\\Packages该脚本位于 C:\\Users\\MyName\\AppData\\Roaming\\Sublime Text 3\\Packages

I can select the script in Tools/Build Systems/build-bat and then I run it via CTRL+B or via manually selecting it in Tools/Build我可以在 Tools/Build Systems/build-bat 中选择脚本,然后通过 CTRL+B 或通过在 Tools/Build 中手动选择它来运行它

It happens exactly nothing.它完全没有发生。 I don't see anything, I don't get any errors.我什么也没看到,我没有收到任何错误。

It should run a file named: build.bat in the current directory where the file that I am working on is placed.它应该在我正在处理的文件所在的当前目录中运行一个名为:build.bat 的文件。 But that doesn't happen.但这不会发生。

Why?为什么?

在向 sublime text 3 添加新的构建系统后,您必须重新启动 sublime text 3。在此之后,上面的代码有效。

You can rename your build.bat to make.bat and choose the Make build system in ST.您可以将build.bat重命名为make.bat并在 ST 中选择 Make 构建系统。 Just press Ctrl+B and ST will try to start make command and make.bat will be executed.只需按Ctrl+B ,ST 将尝试启动make命令并执行make.bat The output will be showen in ST's console.输出将显示在 ST 的控制台中。

This worked for me:这对我有用:


It works with paths and files with whitespaces by spilting up the arguments with "arg" , such as:它通过使用"arg" ,拆分参数来处理带有whitespaces的路径和文件"arg" ,例如:

[..., "/C", "START", "${file_path}", "${file_name}"]


Paste this into your Batch.sublime-build file.将其粘贴到您的Batch.sublime-build文件中。

{
    "file_patterns": ["*.bat"],
    "selector": "source.Batch",
    // This runs the batch file in cmds' console
    "cmd": ["cmd", "/C", "START", "${file_path}", "${file_name}"]
}

Your batch file can then be run in the CMDs' CLI.然后可以在 CMD 的 CLI 中运行您的批处理文件。 I suppose it's possible to pass arguments also but this may be a starting point for you.我想也可以传递参数,但这可能是您的起点。

The above will run cmd.exe and run the code in its native console.以上将运行 cmd.exe 并在其本机控制台中运行代码。 This will accept your inputs of the .bat file.这将接受您对.bat文件的输入。


Here's a build that can be saved as BatchStConsole.sublime-build这是一个可以保存为BatchStConsole.sublime-build 的构建

{
    "file_patterns": ["*.bat"],
    "selector": "source.Batch",
    // This outputs to Sublime Texts' console
    "cmd": ["cmd", "/C", "${file}"]
}

The above will run the code in Sublime Texts' console.上面的代码将在 Sublime Texts 的控制台中运行。 This will not accept your inputs of the .bat file.这不会接受您对.bat文件的输入。 But still useful for debugging as it passes any arguments like the native CLI but just no interaction.但对于调试仍然有用,因为它传递任何参数,如本机 CLI,但没有交互。


Relevant help:相关帮助:

START https://ss64.com/nt/start.html START https://ss64.com/nt/start.html

https://docs.sublimetext.io/guide/usage/build-systems.html https://docs.sublimetext.io/guide/usage/build-systems.html

https://www.sublimetext.com/docs/3/build_systems.html https://www.sublimetext.com/docs/3/build_systems.html

Create new build system and paste this:创建新的构建系统并粘贴:

{
    "file_patterns": ["*.bat", "*.cmd"],
    "selector": "source.Batch",
    // opens CMD window and runs with full features. Uncomment what you like
    // "shell_cmd": "start \"CMD from Sublime - ${file_name}\" call \"${file}\"",
    "cmd": "cmd /c start \"CMD from Sublime - ${file_name}\" call \"${file}\"",

    // works on Sublime Text console and you can't input anything
    // "cmd": "cmd /c \"${file}\""
}

Save it as Batch.sublime-build file.将其保存为Batch.sublime-build文件。 Tested in ST3 and ST4 versions.在 ST3 和 ST4 版本中测试。

{
  "shell_cmd": "${file}",
  "working_dir": "$project_path",
  "windows" : {
      "shell": true
  }
}

then ctrl+ B works on any bat file after restarting sublime.然后 ctrl+ B 在重新启动 sublime 后可以处理任何 bat 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM