Execute bat-file from Notepad++
-
Is there any easy and convenient way to run currently opened bat-file from Notepad++?
For example, with a hotkey or a menu or addon? -
@Anton ,
The File > Open in Default Viewer will run the current file based on its windows filetype assocation, which would run the batch. So Settings > Shortcut Mapper could assign a keystroke to that menu entry, if you wanted.
Or Run > Run…,
$(FULL_CURRENT_PATH)
– which you can Save to a named run-command, and give it a keyboard shortcut -
@Anton said in Execute bat-file from Notepad++:
Is there any easy and convenient way to run currently opened bat-file from Notepad++?
For example, with a hotkey or a menu or addon?Keep in mind that batch files are normally run from a command prompt window. My normal practice has been to edit the batch file in Notepad++ and to then
Alt+Tab
to a command prompt window to test the batch file. Windows does not offer a direct mechanism for an application such as Notepad++ to tell a process such as cmd.exe to execute a batch file. That’s why you need to switch usingAlt+Tab
as Microsoft wants the user to be in control.However, you can “run” a batch file from Notepad++ by telling it to open a new command prompt window and that command prompt runs your batch file. There are two ways to do this:
Add a
file://c:/bin/batch_file.bat
link. When you double-click the link it’ll open a command prompt window that’s running your batch file. When the batch file exits the command prompt window goes away. Thus you likely will want to add aPAUSE
command or some other mechanism for suspending the batch file so you can view the results.Another way is to take advantage of the
Run / Run
command and to point that at your batch file. Unfortunately, there does not see to be a way to add custom entries to the Run menu so that you can set up a Notepad++ keyboard shortcut that runs a a batch file. As with thefile://
links you will end up with a new command prompt window that then vanishes at the end of execution. You can add/K
to the string to
run cmd.exe to keep it open when the batch file terminates though then would then need to manually close those windows. -
Thank you!