Windows command prompt log to a file

后端 未结 3 1172
南旧
南旧 2020-12-08 11:10

I\'d like to easily save the log of the Windows command prompt into a file. Is there any alternative to select everything and right-click on copy?

相关标签:
3条回答
  • 2020-12-08 11:28

    First method

    For Windows 7 and above users, Windows PowerShell give you this option. Users with windows version less than 7 can download PowerShell online and install it.

    Steps:

    1. type PowerShell in search area and click on "Windows PowerShell"

    2. If you have a .bat (batch) file go to step 3 OR copy your commands to a file and save it with .bat extension (e.g. file.bat)

    3. run the .bat file with following command

      PS (location)> <path to bat file>/file.bat | Tee-Object -file log.txt

    This will generate a log.txt file with all command prompt output in it. Advantage is that you can also the output on command prompt.

    Second method

    You can use file redirection (>, >>) as suggest by Bali C above.

    I will recommend first method if you have lots of commands to run or a script to run. I will recommend last method if there is only few commands to run.

    0 讨论(0)
  • 2020-12-08 11:30

    You can redirect the output of a cmd prompt to a file using > or >> to append to a file.

    i.e.

    echo Hello World >C:\output.txt
    echo Hello again! >>C:\output.txt
    

    or

    mybatchfile.bat >C:\output.txt
    

    Note that using > will automatically overwrite the file if it already exists.

    You also have the option of redirecting stdin, stdout and stderr.

    See here for a complete list of options.

    0 讨论(0)
  • 2020-12-08 11:30

    In cmd when you use > or >> the output will be only written on the file. Is it possible to see the output in the cmd windows and also save it in a file. Something similar if you use teraterm, when you can start saving all the log in a file meanwhile you use the console and view it (only for ssh, telnet and serial).

    0 讨论(0)
提交回复
热议问题