Search code examples
cmderror-handlingcommand-promptstderr

How do you shorten the errorcode shown on the console while programming


I have the problem, when I make a bigger mistake while programming, I get errors that each take up 100 lines. The useful errorcode is in the very top, while the rest looks like a copy/paste of the same useless text going something like:

In file included from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39,
                 from 9.2.cpp:1:
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:682:5: note: candidate: 'template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not
_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>
::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _T
p&)'

What can I do to make the window omit this part? I know what the problem is, but I don't want the same line of text spam my entire window all the time.


Solution

  • You can get the error code using this batch file:

    @echo off
    pushd %~dp0
    The command generated the long error 1>nul 2>errors.txt
    set /p errorcode=<errors.txt
    echo %errorcode%
    del /f /q errors.txt
    popd
    goto :eof 
    

    Run it from the cmd and you will get the error code.