VSCode:Code Runner扩展程序无法在git bash终端上执行代码? [英] VSCode: Code Runner extension is unable to execute the code on git bash terminal?

查看:188
本文介绍了VSCode:Code Runner扩展程序无法在git bash终端上执行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个简单的程序"primeRange.cpp",使用适用于VSCode的Code Runner扩展程序.

I am trying to run a simple program "primeRange.cpp" using Code Runner extension available for VSCode.

我在 VSCode 中选择了默认终端为 git bash ,但是当我点击右上角的 Run 时,它将发送命令bash使用g ++编译器运行该程序,但是当存在具有给定名称的目录时,我得到没有这样的文件或目录的错误消息.

I have selected my default terminal as git bash in VSCode, but when I hit Run on top right corner, it sends the command to bash to run the program using g++ compiler, but I am getting error as no such file or directory, when there exists a directory with the given name.

我该如何解决?

当我在代码运行器上按Run时,如何自定义要在bash上命中的命令?

我要将命令设置为:

cd "c:\\Users\\Tushar\\Desktop\\contests\\Practice" && g++ primeRange.cpp -o primeRange && "c:\\Users\\Tushar\\Desktop\\contests\\Practice\\primeRange"

OR

cd "c:\Users\Tushar\Desktop\contests\Practice" && g++ primeRange.cpp -o primeRange && "c:\Users\Tushar\Desktop\contests\Practice\primeRange"

如果我是在bash上手动执行以上任何一个命令,则它可以正常工作.

If I am executing any one of the above command manually on bash then it's working.

所以我基本上想知道如何包括可执行文件路径内的文件名为:

"c:\Users\Tushar\Desktop\contests\Practice\primeRange"

而不是在引号之后:

"c:\Users\Tushar\Desktop\contests\Practice\"primeRange

这是我的 settings.json .

我已将settings.json中的路径更新为:

I have updated the path in settings.json to:

"code-runner.executorMap": {
        "cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && \"./$fileNameWithoutExt.exe\""
    },

但是现在我得到提示,而不是按以下要求输入标准输入:

But now I am getting prompt instead of asking for stdin as given below:

已解决

修正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 为:

Adding another property code-runner.terminalRoot in settings.json as:

"code-runner.terminalRoot": "/"

推荐答案

一段时间以来,我一直遇到相同的问题.经过数小时的网上游荡,我想找到了解决方法.

I was having the same issue for quite some time and after hours of online loitering, I think I found the solution.

windows和unix/linux具有不同的地址命名方式.要寻址d驱动器中名为my_codes的文件夹,Windows将具有以下内容:D:\ my_codes",而Unix/Linux将具有类似这样的名称-"/D/my_codes/".值得注意的区别是使用了不同的斜杠('/'& \).Unix将\视为定界符.因此,送入bash的地址实际上不是bash的正确地址.这就是为什么它会引发错误没有这样的文件或目录"的原因.

windows and unix/linux have different ways of naming the address. To address a folder named my_codes inside d drive, windows will have the following :-" D:\my_codes ", while unix / linux will have something like this-"/D/my_codes/". The difference worth noticing is use of different slashes( '/' & \ ). Unix considers \ as delimiter. So the address being fed to bash is not actually correct address for bash. And that is why it throws the error "No such file or directory".

您是否注意到在bash向您抛出错误"No such file or directory"之前,它删除了地址中的所有反斜杠并显示了'c:UsersTusharDesktopcontestPractice'吗?

Did you notice that just before bash threw you the error "No such file or directory", it removed all the back slashes from the address and presented you 'c:UsersTusharDesktopcontestPractice' ?

幸运的是,此问题已由"Code Runner"解决.开发人员.

luckily this issue has already been resolved by "Code Runner" devs.

您所要做的就是在setting.json文件中包括以下内容:-" code-runner.terminalRoot":"/",

All you have to do is include the following in setting.json file:- "code-runner.terminalRoot":"/",

我希望我能有所帮助.编码愉快.

I hope I was of some help. Happy Coding.

这篇关于VSCode:Code Runner扩展程序无法在git bash终端上执行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆