背景
- 在vscode 中 如果執(zhí)行命令需要傳遞進來參數(shù),那么直接通過命令行終端的方式不太方便。
- 通過task 任務(wù)的方式來進行啟動執(zhí)行,降低反復輸入?yún)?shù)等繁瑣工作。
首先可以查看vscode 官方文檔
.vscode/task.json
示例
執(zhí)行cpp 帶參數(shù)二進制
{"version": "2.0.0","tasks": [{"label": "Run BIN","type": "shell", // shell 類型的任務(wù)"command": "${command:cmake.launchTargetPath}", // CMake 生成的二進制文件路徑"args": ["${workspaceFolder}/config.toml", // 第一個參數(shù)"${workspaceFolder}/model.onnx" // 第二個參數(shù)],"options": {"cwd": "${command:cmake.launchTargetDirectory}"},"group": {"kind": "build", // 此任務(wù)的組別"isDefault": true // 設(shè)為默認任務(wù)},"problemMatcher": [], // 沒有特定的錯誤匹配器"presentation": {"echo": true, // 在輸出面板中回顯命令"reveal": "always", // 始終在面板中顯示"focus": false, // 不聚焦到輸出面板"panel": "new", // 在新面板中顯示輸出"close": false, // 任務(wù)完成后關(guān)閉輸出面板"clear": false // 任務(wù)啟動前清空輸出面板}}]
}
在執(zhí)行task時,手動輸入傳參
- 硬編碼方式雖然比較簡單粗暴,但是,當使用git來管理的時候,會引入一些沒有必要的改變,那么此時就需要將參數(shù),不是使用硬編碼,而是去通過啟動任務(wù)時,動態(tài)加載進去。
- 那就簡單介紹幾種輸入方式
{ // 簡單理解就是輸入文本框"type": "promptString","id": "outputPath","description": "Please input the output path:",},{ // 簡單理解說就是選擇框"type": "pickString","id": "quantize","description": "use quantize","options": [{"label": "True","value": "-q"},{"label": "False","value": ""}],"default": ""},
{"version": "2.0.0","inputs":[{"type": "promptString","id": "outputPath","description": "Please input the output path:",},{"type": "pickString","id": "quantize","description": "use quantize","options": [{"label": "True","value": "-q"},{"label": "False","value": ""}],"default": ""},{"type": "pickString","id": "task","description": "task type","options": ["weigh","arc"],"default": "arc"},{"type": "promptString","id": "config","description": "Please input using configs file",},{"type": "pickString","id": "test_data","description": "juse use test data","options": [{"label": "True","value": "-b"},{"label": "False","value": ""}],"default": ""},{"type": "pickString","id": "qat","description": "use keras quantization aware training","options": [{"label": "True","value": "--qat"},{"label": "False","value": ""}],"default": ""},],"tasks": [{"label": "torch_inf","type": "shell","command": "${command:python.interpreterPath}","args": ["${workspaceFolder}/inference_torch.py","-i","${workspaceFolder}/output/${input:task}/${input:outputPath}"],"presentation": {"echo": true,"reveal": "always","focus": false,"panel": "shared","showReuseMessage": true,"clear": true},"problemMatcher": []},{"label" : "train","type": "shell","command": "${command:python.interpreterPath}","args": ["${workspaceFolder}/test.py","-c","${workspaceFolder}/configs/${input:config}"],"presentation": {"echo": true,"reveal": "always","focus": false,"panel": "shared","showReuseMessage": true,"clear": true},"problemMatcher": []},{"label" : "exprot_tfl","type": "shell","command": "${command:python.interpreterPath}","args": ["${workspaceFolder}/export2.py","-i","${workspaceFolder}/output/${input:task}/${input:outputPath}","${input:quantize}"],"presentation": {"echo": true,"reveal": "always","focus": false,"panel": "shared","showReuseMessage": true,"clear": true},"problemMatcher": []}]
}