CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2019
    Posts
    17

    Is it possible to send verbose o/p of gcc to text file instead of standard output?

    I am trying to run the command :
    $ gcc --save-temps --verbose ex1.c -o ex1__

    and want to save the result in text file rather for easy reference later.
    Am using cygwin 7.3.0, with GNU C version 7.3.0.

  2. #2
    Join Date
    Mar 2019
    Posts
    17

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    $ gcc --save-temps --verbose ex1.c -o ex1__ 2>&1 | tee a.txt

    The above works, but would like to know if any other way exists too, or not. If not, then why not.
    Last edited by ajiten73; March 28th, 2019 at 06:00 AM.

  3. #3
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    Wouldn't normal input redirection work? Say:
    Code:
    $ gcc --save-temps --verbose ex1.c -o ex1 2> gcc_errors.txt
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  4. #4
    Join Date
    Mar 2019
    Posts
    17

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    Quote Originally Posted by laserlight View Post
    Wouldn't normal input redirection work? Say:
    Code:
    $ gcc --save-temps --verbose ex1.c -o ex1 2> gcc_errors.txt
    No, the text file is just created but empty. For a new file (not created yet) used >, but failed. Even using >> (so as to append contents) does not help.

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    When dealing with the console, there are 3 standard streams.

    0 - stdin
    1 - stdout
    2 - srderr

    To redirect stdout to a file use > {fn} (to overwrite) or >>{fn} (to append). To redirect stderr use 2> {fn} (or 2>> {fn}). To redirect stdin use < {fn}.

    By default, both stdout and stderr show their output to the console.

    PS, in your post #2, 2> &1 | tee a.txt

    This causes stderr to go to stdout. stdout is piped (|) to the program tee as stdin. Tee gets its input from stdin (| effectively connects stdout to stdin) and writes its output to both stdout and to the specified file (a.txt).
    Last edited by 2kaud; March 28th, 2019 at 09:23 AM. Reason: PS
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Mar 2019
    Posts
    17

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    Quote Originally Posted by 2kaud View Post
    When dealing with the console, there are 3 standard streams.

    0 - stdin
    1 - stdout
    2 - srderr

    To redirect stdout to a file use > {fn} (to overwrite) or >>{fn} (to append). To redirect stderr use 2> {fn} (or 2>> {fn}). To redirect stdin use < {fn}.

    By default, both stdout and stderr show their output to the console.
    I expected the same, but it leads to a new file (if not already there, with >) which is empty, or causes no change with >> to an existing file.
    I am sorry, but request confirmation for {fn}. I expect it as abbreviation for {file name}.

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    I am sorry, but request confirmation for {fn}. I expect it as abbreviation for {file name}.
    Yes. Also my PS to my post #5.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    I expected the same, but it leads to a new file (if not already there, with >) which is empty, or causes no change with >> to an existing file.
    Do you still get anything showing on the console?

    PS you don't have a space between the 2 and the > do you? It needs to be 2> with no space. 2 > means something different!
    Last edited by 2kaud; March 28th, 2019 at 09:28 AM. Reason: PS
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    Join Date
    Mar 2019
    Posts
    17

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    Quote Originally Posted by 2kaud View Post
    Do you still get anything showing on the console?

    PS you don't have a space between the 2 and the > do you? It needs to be 2> with no space. 2 > means something different!
    $ gcc --save-temps --verbose ex1.c -o ex1__ 2>&1 | tee a.txt
    There is no space between '2' & '>'.
    Would request the meaning (action generated by) of '2 > '.

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    2 > means use 2 as a command-line parameter and redirect stdout (instead of 2> which redirects stderr!).
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  11. #11
    Join Date
    Mar 2019
    Posts
    17

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    Quote Originally Posted by 2kaud View Post
    2 > means use 2 as a command-line parameter and redirect stdout (instead of 2> which redirects stderr!).
    Thanks a lot. Please tell where to look for such information. I request that if some googling term be stated for the same, then even better.

  12. #12
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Is it possible to send verbose o/p of gcc to text file instead of standard output

    See https://support.microsoft.com/en-us/...-stderr-stdout

    If you search https://msdn.microsoft.com/en-us/ with relevant search terms, you usually find required info.

    There's also years of experience!
    Last edited by 2kaud; March 28th, 2019 at 11:33 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured