How to Run a File in the Command Prompt in Windows

The command prompt is a powerful tool on Windows that allows you to run applications, navigate directories, manage files and perform many other tasks through text-based commands

If you need to access or execute a specific file on your computer, the command prompt provides a quick way to do so through some simple commands.

In this comprehensive guide, we’ll explore step-by-step instructions on how to run any file through the command prompt on Windows.

By the end, you’ll have a clear understanding of:

  • How to open the command prompt
  • Navigating to the file location
  • Running executable program files
  • Opening documents like text files
  • Executing scripts like batch files and PowerShell scripts
  • Running installer packages (MSI files)
  • Useful commands for file management
  • Tips and best practices

So let’s get started!

Step 1 – Open the Command Prompt

First, you need to launch the command prompt application. Here are some quick ways to open it:

  • Press Windows key + R to open the Run dialog box. Type cmd and press Enter.

  • Search for ‘Command Prompt’ in the Windows start menu and click to launch it.

  • Open the start menu and scroll down to find the Command Prompt app tile, then click on it.

  • Go to the location C:WindowsSystem32 in File Explorer. Right click on cmd.exe and select Run as administrator.

This will launch the command prompt window ready for you to enter commands.

Step 2 – Navigate to the File Location

Once the command prompt is open, you need to navigate to the folder where your file is located before you can run it.

Use the cd command to change directories by specifying the full file path.

For example:

cd C:UsersMaxDocumentsReports

This will move you into the Reports folder under Documents.

You can use .. to go up a directory level. For example:

cd ..

Moves you up from Reports to Documents.

Use the dir command to list contents of the current folder and confirm you’re in the right location.

Step 3 – Run an Executable Program File

If the file you want to open is an executable program (e.g. .exe, .com file), simply type the name and hit Enter to launch it.

For example, if Calculator.exe is in the current folder, run:

Calculator.exe

This will execute the calculator program.

To open an application located in another folder, provide the full file path before the name:

C:Program FilesNotepad++notepad++.exe

This will run Notepad++ from the Program Files folder.

Step 4 – Open a Document File

To open a document like a text file or PDF, we need to launch the associated application first and pass the file name as a command line argument.

For example, to open report.txt with Notepad:

notepad report.txt

This will open report.txt in a new Notepad window.

For a PDF file, you can use the full Acrobat path:

"C:Program FilesAdobeAcrobat Reader DCReaderAcroRd32.exe" report.pdf

So pass the viewer app path enclosed in quotes, followed by the file name.

Step 5 – Run a Batch File

Batch files are script files containing commands to automate tasks on Windows.

To run a batch file like backup.bat, simply enter its name:

backup.bat

This will execute all the commands within backup.bat in sequence.

Step 6 – Execute a PowerShell Script

To launch a PowerShell script from the command prompt, use the following structure:

powershell -file c:scriptsstart_process.ps1

Make sure to specify the full path to the .PS1 file. This will invoke the PowerShell engine to run the script.

Step 7 – Install an MSI Package

MSI files contain installer packages for Windows applications.

Use the msiexec command to install an MSI, like:

msiexec /i c:installersapp.msi

This will initiate the application installation from the .msi file.

Step 8 – Useful Commands for Files

Here are some helpful commands for file management within the command prompt:

  • dir – List files and folders in current directory
  • copy – Copy files
  • move – Move or rename files
  • mkdir – Create a new folder
  • del – Delete files and folders
  • type – Display contents of a text file
  • cls – Clear the command prompt screen

Tips and Best Practices

Here are some additional tips to use the command prompt effectively:

  • Enclose file paths with spaces in double quotes
  • Use /?" after commands to see usage guide e.g. msiexec /?
  • Add commonly used folders to PATH environment variable
  • Customize the prompt with PROMPT command
  • Learn to pipe command output between multiple commands

The command prompt does take some practice to use fluently, but is well worth learning for the flexibility and productivity it provides once mastered.

how to run file in command prompt

7 Answers 7 Sorted by:

This will leave the console window open even after MyApp.exe terminates:

cmd /K "C:SomeFolderMyApp.exe"

You can create a shortcut with the above. This solution works with all console programs and does not require you to go through Command Prompt every time (or modify the original exe which you usually cant).

Incidentally the /K switch has been around since NT days :-p

Another way, quite useful if the path to the .exe is a complicated one: Start the command prompt and then just drag the .exe file into the cmd window. The full path to the file will be pasted into the prompt and you just have to press enter. No need to cd into any paths.

  • Open command prompt -> Got to your .exes location using cd command -> execute your .exe
  • You can add Console.ReadKey() at the end of your code so that program will wait until the user presses some key.

A way to run a file with cmd and have it stay open:

The “/w” means it waits until the application closes.

If you are on 64bit there here is another example:

This makes sure it still runs as 64bit.

Start menu -> cmd -> cd C:PATHTOYOURFILE -> program.exe

Or add a pause function at the end of your iteration program (assuming you have access to the source)

To save the hassle of having to potentially cd into the correct folder when youre probably already there in windows explorer, simply hold shift, right click on any white space in the folder and click “Open command prompt window here” to open cmd with its directory already set. You can then just type the name of the exe itself

Might want to try a redirect too. I think this is so simple and also adds a persistence to the output message that is non-volatile. c:myapp.exe > c:myapp.dbg

How To Open a File from the Command Prompt In Windows 10/8/7 [Tutorial]

How do I run a program from command prompt?

Open File Explorer (optional). If you don’t know the full path to the program you want to run from the Command Prompt, you can easily find it in File Explorer. To open File Explorer, press Windows key + E, or right-click the Windows Start menu and select File Explorer . If you already know the path to the program, skip to Step 5.

How to run command prompt on Windows 10?

At first, you should open Command Prompt application on your Windows 10 computer. You can press Windows + R, type cmd, and press Enter to open normal Command Prompt or press Ctrl + Shift + Enter to open elevated Command Prompt on Windows 10. Step 2. Run Program from CMD on Windows 10

How to run an EXE file using the command prompt?

In Microsoft Windows, we can use the command prompt or cmd to run an executable file (ending with .exe). Normally we double-click an exe file to execute that file by using cmd we can run an executable program or script without using our mouse. In this article, you will learn how to use the start command to run an exe file using the command prompt.

How do I open a file from a command prompt?

If you want to use Notepad or Paint to open a file from the prompt, just type the full path to the file after the program name. For example, start notepad C:UsersMeDocumentsfile.txt or start mspaint C:UsersmePicturespicture.png. Open the Command Prompt.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *