如何在vscode中构建、运行和删除可执行文件和虚拟文件 我想建立和运行C++源代码。然后删除除源代码以外的所有代码 { "tasks": [ { "type": "shell", "label": "g++ build active file", "command": "/usr/bin/g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", "&", "${fileDirname}/${fileBasenameNoExtension}", "&", "rm ", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "/usr/bin" }, "group": { "kind": "build", "isDefault": true } } ], "version": "2.0.0" }

如何在vscode中构建、运行和删除可执行文件和虚拟文件 我想建立和运行C++源代码。然后删除除源代码以外的所有代码 { "tasks": [ { "type": "shell", "label": "g++ build active file", "command": "/usr/bin/g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", "&", "${fileDirname}/${fileBasenameNoExtension}", "&", "rm ", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "/usr/bin" }, "group": { "kind": "build", "isDefault": true } } ], "version": "2.0.0" },c++,visual-studio-code,C++,Visual Studio Code,我知道他们构建并运行,然后删除无用的文件,但它不起作用。看看,我们可以用dependsOn链接它们。请注意,所需的命令可以包含工具所在位置的完整路径,但操作系统路径变量中不包含该路径,而是选项。cwd应包含工具应运行的路径,即${fileDirname}。此外,您还应该研究presentation参数,并根据希望看到错误的方式对其进行调整 { "version": "2.0.0", "tasks": [ { "type": "shell", "label"

我知道他们构建并运行,然后删除无用的文件,但它不起作用。

看看,我们可以用
dependsOn
链接它们。请注意,所需的
命令
可以包含工具所在位置的完整路径,但操作系统路径变量中不包含该路径,而是
选项。cwd
应包含工具应运行的路径,即
${fileDirname}
。此外,您还应该研究
presentation
参数,并根据希望看到错误的方式对其进行调整

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "g++ build active file",
      "command": "/usr/bin/g++",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}",
      ],
      "presentation": {
        "reveal": "silent",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    },
    {
      "label": "cpp-run",
      "type": "process",
      "command": "${fileDirname}/${fileBasenameNoExtension}",
      "dependsOn": [
        "g++ build active file"
      ],
      "presentation": {
        "reveal": "always",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    },
    {
      "label": "cpp-test",
      "type": "process",
      "command": "rm",
      "args": [
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "dependsOn": [
        "cpp-run"
      ],
      "presentation": {
        "reveal": "never",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    }
  ],
}

在具有作业控制的普通POSIX shell中,单个
&
表示在后台创建作业。它与“逻辑”
&&
运算符有很大不同。我的建议是,你应该多读一些关于贝壳及其工作原理的书。