The basic command to run a file
To run a file from Command Prompt, type the full path to the file followed by Enter. If the file is in your current directory, type just the filename. If it is somewhere else on your computer, type the complete path — for example, C:\Users\YourName\Documents\script.bat — then press Enter.
Command Prompt looks for executable files in specific locations on your system. If a file is not in one of those locations, you must provide the full path or navigate to its folder first using the cd command, which stands for "change directory".
The type of file matters. Some files run directly — batch files (.bat), executable files (.exe), and PowerShell scripts (.ps1). Others require you to call the program that opens them first, like python script.py to run a Python file, or node app.js to run a Node.js file.
Key Takeaways
- Type the filename and press Enter if the file is in your current directory, or type the full path if it is elsewhere on your computer.
- Use the cd command to navigate to a folder, then run the file by name alone — this is simpler than typing long paths repeatedly.
- Some files need the program that runs them specified first, like python filename.py or node filename.js.
- If Command Prompt says "command not recognized", the file path is wrong, the file does not exist, or the program needed to run it is not installed.
Finding the full path to a file
The easiest way to get a file's full path is to open File Explorer, find the file, right-click it, and select "Copy as path". Then paste it into Command Prompt. This avoids typing errors and works whether the file is on your main drive or an external one.
You can also navigate to the file's folder in File Explorer, click the address bar at the top, and copy the folder path. Then in Command Prompt, type that path in quotes if it contains spaces — for example, "C:\Program Files\MyApp" — followed by the filename.
Navigating to a folder before running a file
Instead of typing a full path every time, you can move to the file's folder first. Type cd followed by the folder path. For example, cd C:\Users\YourName\Documents moves you to your Documents folder. After that, type just the filename to run it.
To move up one level in the folder structure, type cd .. (two periods). To see what files are in your current folder, type dir and press Enter. This helps you confirm the file is there before you try to run it.
If the folder path contains spaces, put the entire path in quotes: cd "C:\Program Files\MyApp". Without quotes, Command Prompt stops reading at the first space and returns an error.
Running batch files and executable files
Batch files (.bat) and executable files (.exe) run directly in Command Prompt without needing another program. Type the filename or full path and press Enter. For example, setup.exe or C:\Downloads\installer.exe.
Some executable files open a separate window and return control to Command Prompt immediately. Others run in the background. If you want to see what the program is doing, keep the Command Prompt window open — it may display messages or errors as the file runs.
Running scripts that need an interpreter
Python, Node.js, Ruby, and other languages require an interpreter — a program that reads and runs the script. You must type the interpreter name first, then the script filename. For Python, type python script.py. For Node.js, type node app.js.
Before this works, the interpreter must be installed on your computer and added to your system's PATH, which tells Command Prompt where to find it. If you type python script.py and get "command not recognized", Python is either not installed or not in your PATH. Visit the language's official website to download and install it, and choose the option to add it to PATH during setup.
If you have multiple versions of a language installed, you can specify which one to use. For example, python3 script.py runs Python 3 specifically, while python script.py runs the default version.
Handling errors and permissions
If Command Prompt says "command not recognized" or "is not recognized as an internal or external command", the file does not exist at the path you typed, or the program needed to run it is not installed. Double-check the path by copying it from File Explorer, and verify the filename spelling and extension are correct.
Some files require administrator permissions to run. If you get an "access denied" error, close Command Prompt, right-click it, select "Run as administrator", and try again. Administrator Command Prompt shows "Administrator:" in the title bar.
If a file runs but produces an error, read the error message carefully — it often tells you what went wrong. For scripts, common issues include missing files the script needs, incorrect file paths inside the script, or required programs not being installed.
Running files with arguments and options
Many programs accept arguments — additional instructions you type after the filename. For example, python script.py --verbose runs the script with the verbose flag, which usually makes it print more information. The exact arguments depend on what the program supports.
To see what arguments a program accepts, try typing the filename followed by --help or -h. Many programs display a help menu showing available options. For example, python --help shows Python's options, and node --help shows Node.js options.
Frequently Asked Questions
How do I run a file if the path has spaces in it?
Put the entire path in double quotes. For example, "C:\Program Files\MyApp\program.exe". Without quotes, Command Prompt stops at the first space and cannot find the file. This applies to both the path and the filename.
What is the difference between typing a filename and a full path?
A filename alone — like script.py — only works if the file is in your current directory or in a folder listed in your system's PATH. A full path — like C:\Users\YourName\Documents\script.py — works from anywhere because it tells Command Prompt exactly where to find the file.
Can I run a file by double-clicking it instead of using Command Prompt?
Yes, for most files. Double-clicking an .exe or .bat file runs it directly. However, Command Prompt is useful when you need to see error messages, pass arguments to the program, or run multiple files in sequence. Double-clicking hides these details.
Why does my script run but then the Command Prompt window closes immediately?
Some programs close the window when they finish. To keep it open so you can see the output, type pause on a new line at the end of your batch file, or run the file from an already-open Command Prompt window instead of double-clicking it.
How do I stop a file that is running in Command Prompt?
Press Ctrl+C to stop most running programs. This sends an interrupt signal and returns control to the Command Prompt. If that does not work, close the Command Prompt window, though this may not cleanly shut down the program.