Run .bat from Notepad++
-
Hi,
I have a bat have that I just edited in Notepad++. Instead of going back to desktop and double click to run it, can I directly run form the already opened Notepad++?
Thanks
-
@Adnan-Arshad said in Run .bat from Notepad++:
I have a bat have that I just edited in Notepad++. Instead of going back to desktop and double click to run it, can I directly run form the already opened Notepad++?
One way do to this is to add a
file://c:/path/to/your/batch/file.bat
link to the batch file. Double click it. Doing it this way creates a new command prompt window.Another way is to put this in the
Run / Run
menu
cmd /C "cd $(CURRENT_DIRECTORY) && $(FULL_CURRENT_PATH)"
That is doing three things
- It runs cmd.exe which is the command prompt and batch file processor.
- By default Notepad++ starts cmd in the same directory as Notepad++.exe. We get around this with
cd $(CURRENT_DIRECTORY)
which changes the directory to the same one that your batch file is in. $(FULL_CURRENT_PATH)
is expanded by Notepad++ into the path of the file you are editing, which is your batch file.
This way also created a new command window much like the
file://
link. You will discover that when your batch file ends that the command prompt window vanishes. There are two workarounds.- Put a
PAUSE
statement in your batch file just before it exits. - Or instead of
/C
use/K
- for example:
cmd /K "cd $(CURRENT_DIRECTORY) && $(FULL_CURRENT_PATH)"
Using
/K
keeps the command prompt window after the batch file terminates. If you want to end the batch file and also get rid of the window at the same time then use theEXIT
command in your batch file. -
Thanks for the response,
not sure if my question was clear. I have .bat script already in the Notepad++. Can I use any of the menus in Notepad++ like Run, Edit, Tools etc just to execute the .bat file. If you ask me to open Run command, then I can just go the back to the desktop to run the file which is more easy. Hope my query is clear.
-
Follow the instructions of @mkupper for the Run command, it will do what you want:
Open the menu
Run
, chooseRun...
from the menu and copy either this line:cmd /C "cd $(CURRENT_DIRECTORY) && $(FULL_CURRENT_PATH)"
or this line:
cmd /K "cd $(CURRENT_DIRECTORY) && $(FULL_CURRENT_PATH)"
into the text field (combo box) and hit
Run
button.From this point on, if you want to run your script from within notepad++. Just press F5 on your keyboard or click through the menu again.
-
@Adnan-Arshad said in Run .bat from Notepad++:
Hi,
I have a bat have that I just edited in Notepad++. Instead of going back to desktop and double click to run it, can I directly run form the already opened Notepad++?
Thanks
Yes you can do it in different ways from inside Npp: the one I suggest is to use the plugin called RunMe: you can install it from the Plugin > Plugin Admin dialog, at the TabPage Available:
1 and 2: search in here for “RunMe”
3 check its checkbox
4: hit the Install button (Up Right corner of the Plugin Admin dialog).After install completes (Npp closes, the plugin gets installed and Npp reopens) you will have a new RunMe menu Item inside the Plugin menu and some more buttons onto the Npp toolbar.
So from now on you can open or run the current shown file lunching it into the default program: since the default program to open bat files is MsDos prompt ( command . com interpreter) you can execute directly any bat file just hitting the keyboard shortcut indicated into RunMe menu (or you can even customize it to bind your own preferred shortcut) or in alternative you can hit the button with only the lightning bolt icon.
The RunMe plugin will also allow you to do some other things: to discover what you can do with, after installing it, you can hover the mouse cursor for some seconds without moving it on one of the new RunMe buttons: after a few moments an hint will be shown of what that button does.
For your convenience, some screenshots follow:
-
…or add this line
<Command name="Run &bat" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /K "cd $(CURRENT_DIRECTORY) && $(FULL_CURRENT_PATH)"</Command>
in the section <UserDefinedCommands> of your shortcuts.xml file.
Now you have the command in your “Run” submenu.With “Modify shortcut” you can make a shortcut.
-
Summary:
@mkupper 's advice is excellent. The other repliers (except @wonkawilly ) are really only repeating mkupper’s idea in slightly different ways, hoping that you understand.
wonkawilly suggests using a plugin, which really is a bit of overkill for the original need as stated, unless you really need a button on the toolbar to run the current tab’s batch file.
The only way in which I’d change mkupper’s advice is that this line is a bit unclear to the novice:
One way do to this is to add a
file://c:/path/to/your/batch/file.bat
link to the batch file.What this means is to put that text into a file tab that you’re editing, and then you can double click that text (it will appear as an underlined link) to execute the batch file.
If you want to put it in the batch file itself, a good place might be near the top…you’d have to do it as a comment, e.g.:
rem file://c:/path/to/your/batch/file.bat
-
Hello, @adnan-arshad, @mkupper, @markusbodensee, @wonkawilly, @karlo-f, @alan-kilborn , and All,
Remember that the right syntax of this kind of link is :
file:///<Absolute file path>
and NOT :
file://<Absolute file path>
Indeed, in the second case, if the file path contains
space
characters, which must be replaced by%20
, the link will not work at all !Best Regards,
guy038
-
@Adnan-Arshad said in Run .bat from Notepad++:
not sure if my question was clear. I have .bat script already in the Notepad++. Can I use any of the menus in Notepad++ like Run, Edit, Tools etc just to execute the .bat file. If you ask me to open Run command, then I can just go the back to the desktop to run the file which is more easy. Hope my query is clear.
The direct answer is, no, you can’t do that. Batch files are read and interpreted by cmd.exe.
It sounds like what you are seeking would be a Notepad++ plugin that would read the document and execute the commands as though it was cmd.exe. If a plugin was doing that then I suspect it would likely also be a batch file debugger that would allow for breakpoints, single stepping, display of the current variables, etc. Google for batch file debugger will find that they exist though not built into Notepad++.
-
Can I use any of the menus in Notepad++ like Run … just to execute the .bat file. If you ask me to open Run command, then I can just go the back to the desktop to run the file which is more easy.
If you create a Run menu item for this and then pick a keycombo that will execute this item, how much more easy can it get than to press the chosen keycombo when you want to run it? Certainly this is much easier than mousing over to the desktop and double-clicking something.