visual-studio-code - 使用 Visual Studio Code 进行调试并将终端输出管道传输到文件

标签 visual-studio-code terminal cmake vscode-debugger

我正在使用 VS Code 在 Ubuntu 上调试应用程序,使用 launch.json 文件和 cmake 来构建和调试。这工作正常,我可以按预期在终端中看到程序的输出。但是,我想将此输出自动保存到文件中。我通常会这样做的方式是 mycommand > terminal_output.txt ,但是我找不到使用 launch.json 文件复制它的方法,或者通过终端运行调试(例如,类似于 debug --flags launch.json > terminal_output.txt 的内容)。

这是我的 launch.json 供引用:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++-8 build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++-8 build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

有没有办法以简单的方式做到这一点?

最佳答案

由于我使用的是 cmake,因此我可以使用 cmake.debugConfig 来实现这一点。在我的 settings.json文件:

{
    "cmake.debugConfig": {
        "args": [
            ">",
            "test.txt"
        ]
    }
}

添加 "args"launch.json ,然而,没有奏效。

关于visual-studio-code - 使用 Visual Studio Code 进行调试并将终端输出管道传输到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57871439/

相关文章:

xcode - 在CMake的后期制作步骤中将目标文件复制到另一个位置

node.js - NPM:不推荐使用存在同步

bash - Grep 命令,文件被截断

java - 如何将非图形用户界面的 Java 程序构建为控制台程序

c++ - 在 C++ Ubuntu 中安装 FTP 客户端(库)

linux - qt Creator,找不到可执行文件

intellij-idea - 是否有可以编写 cucumber 步骤定义的 Visual Studio Code 扩展?

node.js - Visual Studio Code 调试器不会在 SAM Local 中的断点处停止

javascript - promise 在 vscode 中异步/等待

linux - Mac OS X 终端 - 我该如何 "clear | java foo"?