The Command Prompt window will automatically close once the batch file is done running. :: This batch file checks for network connection problemsĪfter you run the above script, you’d find a file named results.txt in the same folder as the batch file with the output of the commands. As we’re going to read the output from the text file anyway, we can omit the PAUSE command.
To do so, you’d use the > operator after each command to append its output to the text file. For example, you might want to have your batch script run the above commands and then dump the output to a text file you can view later. There are other directions you could go with a batch file like this. :: Run a traceroute to check the route to So here’s what that might look like: :: This batch file checks for network connection problems. Most people don’t care to see the commands, so this can clean up the output. For example, you’ll see the network connection details but not the “ipconfig /all” line. When you do this, the commands themselves won’t be printed to the Command Prompt, but the results will be. This is typically added to the start of most batch files. You might also want to add the “ECHO OFF” command to the beginning of the file. That makes them a useful way to explain what’s happening in the file for anyone you might give it to–or for your future self, who might forget why you put a certain command in there. Any line that begins with a :: is a comment line and won’t be executed. When we run this file, we’d just see the output of each command right after the other. But this isn’t necessarily the ideal way to write a batch file.įor example, you might want to add comment lines. In the most basic form, we could simply place all those commands in a batch file, one after the other, like so: ipconfig /all We might want to run ipconfig /all to view network information, ping to see if Google’s servers are responding, and tracert to run a traceroute to and see if there are any problems on the way. The only thing you need to change is what you type into Notepad. To run several commands, you type each one on its own line and the batch file will run each one in order.įor example, let’s say we want to write a batch file that runs several network diagnostic commands. It’s fundamentally simple to create a batch file. If you’re running several commands, you could place the PAUSE command in between them. When you want to quickly run commands without seeing the output, you can omit this. In this case, it would print “Hello World” to the window and then immediately close the Command Prompt window. If you didn’t add PAUSE to the file, the batch file would simply run its commands and then automatically close. This particular batch file sets ECHO off (which cleans up the output by hiding the commands from being printed at the prompt, prints the text “Hello World” to the screen, and then waits for you to press a key before it ends.
For example, you might want to name it hello_world.bat.