我正在使用 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/