关于vscode找不到“.exe文件,不是内部命令......“和cmd闪退问题

之前谈到过vscode的C/C++配置的问题,但是使用之后不久会发现会找不到.exe文件并且终端运行之后会出现闪退,然后我研究了一下也查阅了相关的资料,并将最终的配置给出。


首先我在桌面上新建了一个空白的文件夹"Code",然后在Code中又新建了三个文件夹,分别是".vscode"里面放配置文件,"C"里面装C程序,"C++"里面装C++程序,如下图所示。

然后在.vscode中新建四个文件

c_cpp_properties.json

{
    "configurations": [
      {
        "name": "Win64",
        "includePath": ["${workspaceFolder}/**"],
        "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
        "windowsSdkVersion": "10.0.18362.0",
        "compilerPath": "C:/MinGW-W64 GCC/mingw64/bin/g++.exe",
        "cStandard": "c17",
        "cppStandard": "c++17",
        "intelliSenseMode": "gcc-x64"
      }
    ],
    "version": 4
  }

 launch.json

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "(gdb) Launch", 
        "type": "cppdbg", 
        "request": "launch", 
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 
        "args": [], 
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true, 
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\MinGW-W64 GCC\\mingw64\\bin\\gdb.exe",
        "preLaunchTask": "g++",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      }
    ]
  }

settings.json

{
    "files.associations": {
      "*.py": "python",
      "iostream": "cpp",
      "*.tcc": "cpp",
      "string": "cpp",
      "unordered_map": "cpp",
      "vector": "cpp",
      "ostream": "cpp",
      "new": "cpp",
      "typeinfo": "cpp",
      "deque": "cpp",
      "initializer_list": "cpp",
      "iosfwd": "cpp",
      "fstream": "cpp",
      "sstream": "cpp",
      "map": "c",
      "stdio.h": "c",
      "algorithm": "cpp",
      "atomic": "cpp",
      "bit": "cpp",
      "cctype": "cpp",
      "clocale": "cpp",
      "cmath": "cpp",
      "compare": "cpp",
      "concepts": "cpp",
      "cstddef": "cpp",
      "cstdint": "cpp",
      "cstdio": "cpp",
      "cstdlib": "cpp",
      "cstring": "cpp",
      "ctime": "cpp",
      "cwchar": "cpp",
      "exception": "cpp",
      "ios": "cpp",
      "istream": "cpp",
      "iterator": "cpp",
      "limits": "cpp",
      "memory": "cpp",
      "random": "cpp",
      "set": "cpp",
      "stack": "cpp",
      "stdexcept": "cpp",
      "streambuf": "cpp",
      "system_error": "cpp",
      "tuple": "cpp",
      "type_traits": "cpp",
      "utility": "cpp",
      "xfacet": "cpp",
      "xiosbase": "cpp",
      "xlocale": "cpp",
      "xlocinfo": "cpp",
      "xlocnum": "cpp",
      "xmemory": "cpp",
      "xstddef": "cpp",
      "xstring": "cpp",
      "xtr1common": "cpp",
      "xtree": "cpp",
      "xutility": "cpp",
      "stdlib.h": "c",
      "string.h": "c"
    },
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "aiXcoder.showTrayIcon": true
  }

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "g++",
      "command": "g++",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}.exe"
      ],
      "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
          "relative",
          "${workspaceRoot}"
        ],
        "pattern": {
          "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5
        }
      },
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ],
  "presentation": {
    "panel": "new" //默认为“shared“表示共享,改成new之后每个进程创建新的端口
  }
}

运行的过程中会发现,出现端口被占用然后打不开终端的问题,所以我在tasks.json最后加上了presentation,表示每个进程创建新的端口。

然后运行可能会出现能打开终端但是会出现闪退的情况,这时候在我们写的代码下面加上"getchaer()"就可,下面给出2-1000内的质数快去测试试试吧~

#include <stdio.h>
int main()
{
    int i = 0, j = 0;
    for (i = 3; i < 1000; i++)
    {
        for (j = 2; j < i; j++)
        {
            if (i % j == 0)
            {
                break;;
            }
        }
        if (i == j)
        {
            printf("%d ", i);
        }
    }

    getchar();

    return 0;
}

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当在执行CMD指令如ipconfig时遇到“不是内部或外部命令,也不是可运行程序或批处理文件”的情况时,可以采取以下几个步骤来解决问题。 首先,尝试在命令后加上“.exe”后缀再运行,如果能正常运行则说明是系统环境变量PATHEXT没有设置好。可以参考中的方法来设置好PATHEXT。 其次,检查系统path环境变量是否设置正确。如果不正确,需要修改为正确的路径。可以参考中的方法来修复path环境变量。 最后,如果系统环境变量全部设置正确后还是无法解决问题,可以进入相应的系统目录如C:\Windows\System32\,查看对应的ipconfig.exe文件是否存在。如果不存在,则说明对应文件缺失,可以尝试从其他电脑上拷贝一份ipconfig.exe文件过来。这样应该可以解决该问题。参考提供的方法。 总结来说,问题出现的原因可能是系统环境变量PATHEXT没有设置好,path环境变量设置错误或者对应的可执行文件缺失。通过逐步排查并修复这些问题,应该可以解决“不是内部或外部命令,也不是可运行程序或批处理文件”的错误提示。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [CMD提示不是内部或外部命令,也不是可运行程序或批处理文件的解决方法](https://blog.csdn.net/nako1999/article/details/121064036)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [idea 控制台或cmd窗口报’mvn’ 不是内部或外部命令,也不是可运行程序 或批处理文件。](https://download.csdn.net/download/weixin_38571104/14038781)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值