Skip to main content

How to Open Notepad from a Batch Script

Notepad (notepad.exe) is the classic, lightweight text editor built into every version of Windows. In batch scripting, launching Notepad is a common task for several reasons: to display a text file for the user to read, to allow a user to edit a configuration file, or simply to open a blank window for jotting down notes.

This guide will teach you the simple and direct methods for launching Notepad. You will learn how to open a blank instance, how to open a specific file, and the best practices for using the START command to launch it without halting your script.

The Core Command: notepad.exe

The executable for Notepad is notepad.exe. Because its location (C:\Windows\System32) is included in the system's PATH environment variable by default, you can run it directly by name from any command prompt.

Syntax for Opening a File: notepad.exe "path\to\file.txt"

If you provide a path to a file that does not exist, Notepad will prompt you to create it.

When you run notepad.exe directly from a batch script, your script will stop and wait until you close the Notepad window. This is "blocking" behavior. For most scripts, you want to launch Notepad and have your script continue running. The START command is the tool for this.

Syntax: START "" notepad.exe "path\to\file.txt"

  • START: Launches the command in a new, separate process.
  • "": A crucial "dummy" title to ensure paths with spaces are handled correctly.

This is the recommended method for launching any GUI application from a script.

Basic Example: Opening a Blank Notepad Window

This script simply launches a new, empty instance of Notepad.

@ECHO OFF
ECHO --- Launching Notepad ---
ECHO.
ECHO A new, blank Notepad window will now open.
ECHO The script will continue without waiting for you to close it.

START "" notepad.exe

When you run this, a Notepad window will appear, and the command prompt will immediately show that the script has finished.

Opening a Specific Text File

This is the most common use case. You want your script to open an existing file for the user to view or edit.

@ECHO OFF
SET "LogFile=C:\Logs\application.log"

ECHO --- Opening a Log File ---
ECHO.
ECHO The log file at the following location will now be opened in Notepad:
ECHO "%LogFile%"
ECHO.

IF NOT EXIST "%LogFile%" (
ECHO [ERROR] The log file was not found.
PAUSE
GOTO :EOF
)

START "" notepad.exe "%LogFile%"

This script first checks if the file exists and then uses the robust START "" syntax to open it.

Common Pitfalls and How to Solve Them

Problem: The Script Pauses Until Notepad is Closed

This happens when you launch notepad.exe directly, without using the START command.

Example of script with error:

ECHO Opening Notepad...
notepad.exe "readme.txt"
ECHO This line will not be displayed until you close Notepad.

Solution: Always use the START command to launch GUI applications like Notepad. This runs the program in a non-blocking way, allowing your script to continue its work.

Problem: The File Path Contains Spaces

If the path to the file you want to open contains spaces, you must handle it correctly.

Exmaple of script with error:

REM This will FAIL if the path has spaces.
START notepad.exe C:\My Documents\notes.txt

Solution: Quote the path and use the dummy title syntax for the START command.

REM This is the correct, safe syntax.
START "" notepad.exe "C:\My Documents\notes.txt"

Practical Example: A "Create and Edit" Notes Script

This script creates a new, timestamped text file in the user's Documents folder and then immediately opens it in Notepad so the user can start taking notes.

@ECHO OFF
SETLOCAL

ECHO --- Quick Note Taker ---
ECHO.

REM Create a timestamp in YYYY-MM-DD_HH-MM-SS format
SET "Timestamp=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%_%TIME::=-%"
SET "Timestamp=%Timestamp: =0%"
SET "Timestamp=%Timestamp:,=%"
SET "NoteFile=%USERPROFILE%\Documents\Note_%Timestamp%.txt"

ECHO A new note file will be created at:
ECHO "%NoteFile%"
ECHO.

ECHO Creating the file and launching Notepad...

REM Create an empty file first
TYPE NUL > "%NoteFile%"

REM Open the new, empty file in Notepad
START "" notepad.exe "%NoteFile%"

ECHO.
ECHO --- Script finished ---
ENDLOCAL

Conclusion

Launching Notepad from a batch script is a simple task that is useful for a wide range of user-interactive scripts.

Key takeaways:

  • To open a blank window, use START "" notepad.exe.
  • To open a specific file, use START "" notepad.exe "path\to\file.txt".
  • Always use the START command to prevent your script from pausing.
  • Always use the START "" ... syntax with a dummy title to reliably handle paths that contain spaces.