To continuously write ping results to a notepad file with the date and time in Windows, you can use a batch script with the command prompt. Follow these steps:
- Create a new batch script:
Create a new text file, and change its extension from .txt
to .bat
. For example, name it ping_script.bat
.
- Edit the batch script:
Right-click on the newly created batch file and choose “Edit” to open it in Notepad. Add the following lines to the script:
@echo off
set target_address=google.com
set output_file=C:\path\to\output\file.txt:ping_loop
echo %date% %time% >> %output_file%
ping %target_address% >> %output_file%
timeout /t 60 /nobreak
goto ping_loop
Replace google.com
with the IP address or hostname of the target you want to ping, and C:\path\to\output\file.txt
with the desired location and filename for your output file (e.g., C:\Users\YourUsername\Documents\ping_result.txt
).
- Save and close the batch script:
Save the changes to the batch script and close the text editor.
- Run the batch script:
Double-click on the ping_script.bat
file to run the script. This will continuously ping the target address and append the results, along with the current date and time, to the specified output file. The script will ping the target every 60 seconds (timeout value).
- View the results:
Navigate to the specified location in Windows File Explorer and open the text file to view the ping results with date and time.
- Stop the batch script:
To stop the continuous ping and script execution, switch to the Command Prompt window running the script and press Ctrl + C
. This will terminate the script and close the Command Prompt window.
Note: The batch script will run indefinitely until it’s manually stopped. You can adjust the timeout
value in the script (in seconds) to change the interval between pings.