logo elektroda
logo elektroda
X
logo elektroda

CMD - How to Save Console Output to File in Real Time Without Buffering

.:aspire:. 21738 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 13331765
    .:aspire:.
    Level 23  
    Hello. I would like to write the output of a console program to a text file.
    In general, I know what commands to use. The problem is that the result is always saved after the program executes. So the result is buffered, the program executes and then the whole log is saved.
    And I would like the log to be saved "live" without buffering the text (result).
  • ADVERTISEMENT
  • Helpful post
    #2 13335468
    mdmyt
    Level 13  
    Hello.
    Syntax: command_with_parameters> path for the file
    Example: ping elektroda.pl -t> D: \ file.txt
    The ping result will be written to file.txt on drive D
  • ADVERTISEMENT
  • #3 13337164
    .:aspire:.
    Level 23  
    Thank you for the answer, but I know this command. The problem is that I use an application that takes a few minutes to execute. And a normal redirect will only work after this app has been executed. I would like to view the log in a text file while the program is running.
    So the idea is that exe'k should not cache the results.
  • ADVERTISEMENT
  • #5 13355478
    .:aspire:.
    Level 23  
    Unfortunately it does not work :(
  • #6 13370288
    phaxe
    Level 13  
    .:aspire:. wrote:
    Unfortunately it does not work :(

    For me, it works, for example, when copying files:

    XCOPY "X:\katalog\*.*" "Y:\katalog\" /E /K /H /Y /D | tee D:\wynik.txt

    The copy result goes to the screen and to the result.txt file simultaneously
  • ADVERTISEMENT
  • #7 13370470
    marek003
    Level 40  
    What else are you talking about.

    You are talking about a single command and the author is talking about a console application / program.

    To the author
    Perhaps it is worth rethinking (remembering) how the program works in "console mode".

    If you were to see it on the fly, you would need to change (edit and correct) the application you have, in other words, with each "internal command" of your "application" you would have to put code to throw information.
    Now the question: where?

    Just "txt" would not be enough in this case because after each command returning information to the txt file you would have to refresh (reopen) this text file.
    Alternatively, it would remain watching the console window if the results were returned to the screen.
  • #8 16990232
    piotr_be
    Level 11  
    I ran into this thread having a similar problem, this time not redirecting anything from the screen to a text file. I am writing here so as not to clutter the forum with a new topic unnecessarily, especially since the problem is solved, so only for someone who happens to him in a similar way.

    Recommendation composer install

    Standard: composer install> result.txt

    But in the result.txt file, I don't have everything I can see on the screen.
    It turns out that the result visible on the screen is printed partly on STDERR and partly on STDOUT.

    To save everything that is visible on the screen to a file, you need to write:
    composer install> result.txt 2> & 1

Topic summary

The discussion revolves around the challenge of saving the output of a console application to a text file in real-time, rather than after the program has completed execution. The initial suggestion involves using a simple output redirection command, but the user clarifies that this does not meet their needs due to the application's lengthy execution time. A solution is proposed to use the `tee.exe` utility, which allows simultaneous output to both the console and a file. However, the user reports that this method does not work for their specific application. Further responses suggest that for console applications, modifying the application to output logs continuously may be necessary, or alternatively, capturing both standard output (STDOUT) and standard error (STDERR) streams to ensure all visible output is logged.
Summary generated by the language model.
ADVERTISEMENT