【发布时间】:2020-07-03 18:38:42
【问题描述】:
我正在尝试使用可用于 VSCode 的 Code Runner 扩展来运行一个简单的程序“primeRange.cpp”。
我在 VSCode 中选择了我的默认终端为 git bash,但是当我点击右上角的 Run 时,它会发送命令bash 使用 g++ 编译器运行程序,但是当存在具有给定名称的目录时,我收到错误,因为 没有这样的文件或目录。
我该如何解决这个问题?
当我在代码运行器上按运行时,如何自定义要在 bash 上执行的命令?
我想将命令设置为:
cd "c:\\Users\\Tushar\\Desktop\\contests\\Practice" && g++ primeRange.cpp -o primeRange && "c:\\Users\\Tushar\\Desktop\\contests\\Practice\\primeRange"
或
cd "c:\Users\Tushar\Desktop\contests\Practice" && g++ primeRange.cpp -o primeRange && "c:\Users\Tushar\Desktop\contests\Practice\primeRange"
如果我在 bash 上手动执行上述任何一个命令,那么它就可以工作了。
所以我基本上想知道如何包含可执行文件 路径内的文件名为:
"c:\Users\Tushar\Desktop\contests\Practice\primeRange"
而不是在引号之后:
"c:\Users\Tushar\Desktop\contests\Practice\"primeRange
我已将 settings.json 中的路径更新为:
"code-runner.executorMap": {
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && \"./$fileNameWithoutExt.exe\""
},
已解决
修复 1:
将 settings.json 中的 code-runner.executorMap 属性更新为
"code-runner.executorMap": {
"cpp": "cd $dirWithoutTrailingSlash && g++ -std=c++11 $fileName -o $fileNameWithoutExt && ./$fileNameWithoutExt"
}
修复 2:
在 code-runner.terminalRoot 中添加另一个属性 settings.json 为:
"code-runner.terminalRoot": "/"
【问题讨论】:
标签: bash visual-studio-code vscode-tasks vscode-code-runner