Sublime Text 2 build via simple batch file

我怕爱的太早我们不能终老 提交于 2019-12-20 12:17:10

问题


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.




回答3:


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

http://docs.sublimetext.info/en/latest/reference/build_systems/configuration.html#platform-specific-options

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



来源:https://stackoverflow.com/questions/10068264/sublime-text-2-build-via-simple-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!