Windows cmd batch file write multiple netstat outputs to text file

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

To write multiple netstat outputs to a text file in a Windows batch file, you can use the >> operator to append the output to the file. Here's an example:

batch
@echo off
setlocal

REM Specify the output file
set "outputFile=netstat_output.txt"

REM Perform multiple netstat commands and append the output to the file
netstat -a >> "%outputFile%"
netstat -n >> "%outputFile%"
netstat -o >> "%outputFile%"

REM End of the batch script

In this example, the netstat commands are executed one after the other, and the output of each command is appended to the specified outputFile. You can add more netstat commands or modify the existing ones as needed.

Make sure to adjust the value of the outputFile variable to the desired path and filename for the output file. The >> operator is used to append the output to the file. If the file doesn't exist, it will be created. If it already exists, the output will be appended to the existing content.

After executing the batch script, the netstat outputs will be saved in the specified text file.