How to run a batch file using the command line on Windows

Author: Mark Sanchez
Date Of Creation: 5 January 2021
Update Date: 29 June 2024
Anonim
executing batch file in the command-line in windows and concatenating file to standard output
Video: executing batch file in the command-line in windows and concatenating file to standard output

Content

In this article, we are going to show you how to run a batch file (BAT file) on Windows using the command line. The file can be run from the Run window or from the Command Prompt window.

Steps

Method 1 of 2: Run Window

  1. 1 Click on ⊞ Win+R. The Run window will open.
    • To run the batch file as an administrator, use the method described in the next section.
  2. 2 Click on Overview.
  3. 3 Open the folder with the BAT file.
  4. 4 Click on the batch file to highlight it.
  5. 5 Click on Open. The Run window displays the path to the batch file.
  6. 6 Click on OK. The BAT file will be launched (this will open a command prompt window). When the batch file finishes running, the message “Press any key to continue” is displayed at the bottom of the Command Prompt window.
  7. 7 Press any key. The command prompt window will close.

Method 2 of 2: Command Prompt Window

  1. 1 Open the start menu . To do this, click on the Windows logo in the lower left corner of the screen.
  2. 2 Enter cmd in the start menu search bar. The search results are displayed.
  3. 3 Right click on Command line. A menu will open.
  4. 4 Click on Run as administrator. A confirmation message will be displayed on the screen.
  5. 5 Click on Yes. This will launch Command Prompt as an administrator.
  6. 6 Enter the command cd, and then enter the path to the folder with the BAT file. For example:
    • If the batch file is located on the desktop, enter cd Users Username Desktop.
    • If the batch file is located in the Downloads folder, enter cd Users Username Downloads.
    • If you don't know your username, enter cd Usersand then press ↵ Enterto go to the Users folder.Now enter dirand then press ↵ Enterto view a list of usernames.
  7. 7 Click on ↵ Enter. The current directory will change to the folder with the BAT file.
  8. 8 Enter a name for the batch file. For example, if it's called "program.bat", enter program.bat.
    • If you don't know the file name, enter dirand then press ↵ Enterto open a list of all files stored in the folder. Find the required BAT file in the list.
  9. 9 Click on ↵ Enter. The batch file will run.