问题描述
在我的研究中,我使用有限元方法,我们使用Abaqus的求解器,该求解器使用Fortran制作的子例程,而我使用vs代码进行编辑。因此,为了运行我的代码,我制作了一个批处理文件,该文件使此过程更简单(以避免在cmd中键入许多指令)。
在此图像中,您可以看到我的工作目录中的文件,如果可以直接从vs代码设置快捷方式来执行principal.bat文件,另一个快捷方式来终止.bat,则可以节省很多时间: {0}} 感谢您的帮助,为此我已经尝试设置task.json文件,但我有点迷茫。
解决方法
您可以使用扩展名multi-command在终端上键入批处理文件命令
将此添加到您的settings.json
:
"multiCommand.commands": [
{
"command": "multiCommand.callPrincipal","sequence": [
{ "command": "workbench.action.terminal.sendSequence","args": { "text": "principle.bat\u000D" }
}
]
},{
"command": "multiCommand.callTerminate","args": { "text": "terminate.bat\u000D" }
}
]
}
]
然后在keybindings.json
{
"key": "shift+alt+F1",// or any other key combo
"command": "multiCommand.callPrincipal"
},{
"key": "shift+alt+F2",// or any other key combo
"command": "multiCommand.callTerminate"
}
您可以添加when
子句以限制键绑定的有效性
修改
当您只需要1个终端命令时,不需要使用multi-command
扩展名,您可以定义键绑定的参数
{
"key": "shift+alt+F1",// or any other key combo
"command": "workbench.action.terminal.sendSequence","args": { "text": "principle.bat\u000D" }
},"args": { "text": "terminate.bat\u000D" }
}
或者,您可以定义2个任务来启动批处理文件并使用 Terminal |运行它们。 运行任务... 。
如果将一个指定为构建任务,则可以使用快捷键。
我找不到运行命名任务的命令,因此可以在键盘绑定中使用它。
,您可以添加调试配置,然后使用 F5 启动该配置。
这里的cppvsdbg
类型并不重要,因为您不能(也不想)调试批处理文件。
Shift-F5 终止批处理
launch.json
{
"version": "0.2.0","configurations": [
{
"name": "Start batch","type": "cppvsdbg","request": "launch","program": "cmd.exe","args": [
"/c","principal.bat"
],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false
}
]
}