- 1 year ago
Pipe cerr to some file in c++ 17 build system for sublime text 3
To redirect std::cerr
to a file in a C++17 build system for Sublime Text 3, you can modify the build system configuration to capture the standard error output and save it to a file. Here's an example:
Open Sublime Text and go to "Tools" -> "Build System" -> "New Build System". This will create a new build system configuration file.
Replace the default content with the following code:
json{
"cmd": ["your_compiler_executable", "$file"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "$file_path",
"quiet": true,
"shell_cmd": "your_compiler_executable \"$file\"",
"variants": [
{
"name": "Capture Stderr",
"shell_cmd": "your_compiler_executable \"$file\" 2> \"$file_base_name.err\""
}
]
}
Replace
"your_compiler_executable"
with the actual path or command of your C++ compiler.Save the file with a meaningful name and
.sublime-build
extension. For example, you can save it ascpp_with_stderr_capture.sublime-build
.Configure your project to use the newly created build system:
- Go to "Project" -> "Edit Project" and add the following configuration:json
"build_system": "Packages/User/cpp_with_stderr_capture.sublime-build"
- Save the project file.
- Go to "Project" -> "Edit Project" and add the following configuration:
Now, when you build your C++ code using the configured build system in Sublime Text 3, the standard error output (std::cerr
) will be redirected to a file with the same base name as your source file but with the .err
extension. For example, if your source file is main.cpp
, the error output will be saved to main.err
.
You can modify the build system configuration further to suit your specific requirements, such as customizing the compiler flags, defining build variants, etc.