7

I have the following script called "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

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

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. But that doesn't happen.

Why?

Simon S.
  • 563
  • 4
  • 21

5 Answers5

4

After adding a new build system to sublime text 3 you have to restart sublime text 3. After this the code above works.

Simon S.
  • 563
  • 4
  • 21
3

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. Tested in ST3 and ST4 versions.

0

You can rename your build.bat to make.bat and choose the Make build system in ST. Just press Ctrl+B and ST will try to start make command and make.bat will be executed. The output will be showen in ST's console.

viktor-zin
  • 181
  • 1
  • 3
0

This worked for me:


It works with paths and files with whitespaces by spilting up the arguments with "arg" , such as:

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


Paste this into your Batch.sublime-build file.

{
    "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. 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. This will accept your inputs of the .bat file.


Here's a build that can be saved as 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. This will not accept your inputs of the .bat file. But still useful for debugging as it passes any arguments like the native CLI but just no interaction.


Relevant help:

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

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

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

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Ste
  • 1,729
  • 1
  • 17
  • 27
0
{
  "shell_cmd": "${file}",
  "working_dir": "$project_path",
  "windows" : {
      "shell": true
  }
}

then ctrl+ B works on any bat file after restarting sublime.

Paul Sumpner
  • 447
  • 7
  • 8