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

问题描述 投票:0回答:3

我正在使用 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"
        }
    ]
}

有没有一种简单的方法可以做到这一点?

visual-studio-code terminal cmake vscode-debugger
3个回答
2
投票

由于我使用的是 cmake,所以我能够在我的

cmake.debugConfig
文件中使用
settings.json
来实现此目的:

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

但是,在

"args"
中添加
launch.json
不起作用。


1
投票
  1. 安装 CodeLLDB 扩展

  2. launch.log:在 CodeLLDB 启动配置中添加

    “stdio”:[null,null,“debug.log”] // stdin / stdout / stderr

CodeLLDB 的 stdio 重定向


0
投票

我知道这很旧,但这很有魅力!谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.