Windows command prompt log to a file

后端 未结 3 1180
南旧
南旧 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)> /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.

提交回复
热议问题