Sublime Text 2 build via simple batch file

2019-03-25 03:49发布

问题:

I've been playing a bit with ST2 and it seems like a pretty cute editor. Unfortunatelly, its documentation is horrible.

And I'm being nice. So here's my question.

I have five files in a directory, which I usually build via a .bat file with

ifort file1.f90 file2.f90 file3.f90 ...

how can I define and execute this line on windows cmd (taking account the enviromental variables like PATH) from ST2 via a shortcut and see the output? Is something like that even possible at this stage with ST2?

回答1:

I just made a new build like this:

{
    "cmd": ["$file"],
    "selector": "source.dosbatch"
}

Then you would put your ifort ... string in a .bat file and "build" that.



回答2:

Here's a step by step way to run a batch file as part of your build process:

In Sublime Text 2 go to Tools -> Build System -> New Build System

You'll be presented with a new text file with the following code in it:

{
"cmd": ["make"]
}

Now change the "make" to the exact path of your batch file so it looks something like this:

{
"cmd": ["D:\\xampp\\htdocs\\myproject\\dostuff.bat"]
}

Notice you must use double backslash for windows paths.

Then save this file out as myproject.sublime-build in the default directory it asks you to save it in (should be $HOME_DIR/AppData/Roaming/Sublime Text 2/Packages/User).

Then in your project go back to Tools -> Build System and select the build system that is the same name as the file you just created (in this case it's "myproject").

Hit ctrl + b or go to tools -> build and your batch file should run and output will appear in the ST2 console.