Launching .BAT file with paramater
-
Hi all!
I am editing a source file that needs to be compiled via command line. I wrote a batch file to do this. I configured the Run (F5) option in NP++ to launch the batch. That is working fine, but I need to pass the filename of the file that I am working on in the current NP++ tab. Any way to do this? Thanks! Saga -
You could check the fine manual HERE for that and other good nuggets of information, but for what you want I think you just need to embed
$(FULL_CURRENT_PATH)
into your Run menu command line. -
Thank you! That worked!
Just a note to say that I did look at the documentation. I didn’t find any information on how to pass the file name of the current tab to the called process.
Once you provided $(FULL_CURRENT_PATH), I searched for it in the documentation. Either I searched incorrectly, or there was no reference to this there.
I appreciate your help. Saga
-
@Salvador-Garcia said in Launching .BAT file with paramater:
I searched for it in the documentation. Either I searched incorrectly,
There’s a table defining all the
$(...)
variables at https://npp-user-manual.org/docs/config-files/#userdefinedcommands -
Outstanding! Thanks!
I have another question for you all.
I defined the the process to run using the Run/Run dialog. Currently it looks like the following:
E:\BuildDev\BuildApp.bat $(FULL_CURRENT_PATH)
When I click on the Run button within that dialog it runs fine, but when I run this process by using the main Run menu then selecting the newly created shortcut, it does not pass the $(FULL_CURRENT_PATH) parameter.
What could I be missing here. Again, thanks all! Saga
-
Have you exited and restarted Notepad++? If so, could you look in
%AppData%\Notepad++\shortcuts.xml
and find the entry for that saved userdefinedcommand entry, and paste it here? I am wondering if it didn’t get saved properly. -
OK, weird. I changed the short cut keys from Shift F5 to Alt Shift R and it worked. Thanks again!
OK, so I check the shortcut.xml which I post below. In most entries, it includes passing the parameter, but not in the item that I defined. XML file:
<NotepadPlus>
<InternalCommands />
<Macros>
<Macro name=“Trim Trailing Space and Save” Ctrl=“no” Alt=“yes” Shift=“yes” Key=“83”>
<Action type=“2” message=“0” wParam=“42024” lParam=“0” sParam=“” />
<Action type=“2” message=“0” wParam=“41006” lParam=“0” sParam=“” />
</Macro>
</Macros>
<UserDefinedCommands>
<Command name=“Launch in Firefox” Ctrl=“yes” Alt=“yes” Shift=“yes” Key=“88”>firefox “$(FULL_CURRENT_PATH)”</Command>
<Command name=“Launch in IE” Ctrl=“yes” Alt=“yes” Shift=“yes” Key=“73”>iexplore “$(FULL_CURRENT_PATH)”</Command>
<Command name=“Launch in Chrome” Ctrl=“yes” Alt=“yes” Shift=“yes” Key=“82”>chrome “$(FULL_CURRENT_PATH)”</Command>
<Command name=“Launch in Safari” Ctrl=“yes” Alt=“yes” Shift=“yes” Key=“65”>safari “$(FULL_CURRENT_PATH)”</Command>
<Command name=“Get PHP help” Ctrl=“no” Alt=“yes” Shift=“no” Key=“112”>http://www.php.net/$(CURRENT_WORD)</Command>
<Command name=“Wikipedia Search” Ctrl=“no” Alt=“yes” Shift=“no” Key=“114”>https://en.wikipedia.org/wiki/Special:Search?search=$(CURRENT_WORD)</Command>
<Command name=“Open file in another instance” Ctrl=“no” Alt=“yes” Shift=“no” Key=“117”>$(NPP_FULL_FILE_PATH) $(CURRENT_WORD) -nosession -multiInst</Command>
<Command name=“Send via Outlook” Ctrl=“yes” Alt=“yes” Shift=“yes” Key=“79”>outlook /a “$(FULL_CURRENT_PATH)”</Command>
<Command name=“Launch asm2bin” Ctrl=“no” Alt=“no” Shift=“yes” Key=“116”>E:\CoCoDev\asm2bin.bat</Command>
</UserDefinedCommands>
<PluginCommands />
<ScintillaKeys />
</NotepadPlus>$(FULL_CURRENT_PATH) is missing here. I don;t like repeating myself, but weird.
-
If I try a simple test of a Run menu entry, e.g. :
cmd /K echo $(FULL_CURRENT_PATH)
it works, and then if I save it to a name such as “test” and restart Notepad++, “test” is still there and still works, and is in
shortcuts.xml
:<Command name="test" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /K echo $(FULL_CURRENT_PATH)</Command>
So, I’d guess that your Notepad++ is older (I’m using 7.9.3) and perhaps has a problem with this (although I’ve been around a while and don’t recall any such problem).
You didn’t state your version, but I see in your shortcuts.xml data that you have “Launch in (browser)” commands, and those were removed some time ago, so this tells me your Notepad++ is fairly out of date.
I’d recommend updating and then repeating your efforts with FULL_CURRENT_PATH.
-
Thanks Alan.
v7.9.1 Win 32 bit
I will update. Saga
Update: When I chose to update Notepad++, I get a message indicating that there are no updates. ???
-
Can you post your debug-info which is available from the ? menu, the last menu item?
-
@Salvador-Garcia said in Launching .BAT file with paramater:
Update: When I chose to update Notepad++, I get a message indicating that there are no updates. ???
You can go to the Notepad++ download site for a newer version than your 7.9.1, but perhaps @Ekopalypse has a troubleshooting idea for you, so perhaps you should hold off on that.
-
It’s more curiosity. I’m trying to understand why it doesn’t work.
-
@Alan-Kilborn wrote:
this tells me your Notepad++ is fairly out of date.
Not necessarily. As a reminder, the updater does not overwrite existing config files. So it really says that the version currently being used had been updated from an installation that still had those launch-in-browser commands.
@Salvador-Garcia said in Launching .BAT file with paramater:
v7.9.1 Win 32 bit
Update: When I chose to update Notepad++, I get a message indicating that there are no updates. ???v7.9.1 is the most recent Notepad++ that has had the auto-update triggered (and came long after the launch-in-browser commands were removed from the Run menu). v7.9.2 and v7.9.3 were never deemed stable enough to push to auto-update; and v7.9.4 is still in Release Candidate (“RC”) mode.
I changed the short cut keys from Shift F5 to Alt Shift R and it worked.
I am confused. Was the problem you were having that Shift+F5 wasn’t running your user-defined-command? Or was the problem that the user-defined-command wasn’t running, even when you manually selected it from the menu, it never ran? Or was the problem that it runs the batch file just fine, but doesn’t include the path name? (I thought it was the third option, until you mentioned the Shift+F5 vs Alt+Shift+R.)
Also, you never showed the results of the experiment that @Alan-Kilborn asked you to try. And you haven’t responded to @Ekopalypse’s request for ?-menu Debug Info.
I took a fresh v7.9.1 portable (straight from the zipfile, no customizations yet), and replicated Alan’s experiment:
- Exit all instances of Notepad++
- Run Notepad++
- Run > Run
- set the program to
cmd /K echo $(FULL_CURRENT_PATH)
as @Alan-Kilborn suggested - click Save…
- give it the name
DebugFullCurrentPath
- give it the shortcut
Shift+F5
- click OK => it should be saved now
- click Cancel to exit the menu, or Run to run the command now that you’ve saved it.
- I know, Cancel seems counter-intuitive; but since you hit the OK already, it really did save.
- typing
Shift+F5
ran the command and printed the full current path. So does Run > DebugFullCurrentPath - Looking at Run > Modify Shortcut / Delete Command will show you whether or not you have a shortcut conflict: if you do, it will highlight the offending entry red.
- if you have a conflict, that would explain why
Shift+F5
didn’t work butAlt+Shift+R
did “work”.
- if you have a conflict, that would explain why
- Exit all instances of Notepad++
- Run Notepad++
- File > Open:
%AppData%\Notepad++\shortcuts.xml
(see 🛈 below)
… so that is what I would expect<Command name="DebugFullCurrentPath" Ctrl="no" Alt="yes" Shift="no" Key="112">cmd /K echo $(FULL_CURRENT_PATH)</Command>
My guess is that you originally saved your
Launch asm2bin
command without the$(FULL_CURRENT_PATH)
, and that the next time, when you edited the command to beE:\CoCoDev\asm2bin.bat $(FULL_CURRENT_PATH)
, you forgot to Save… and assign the name. For reference, if you assign the same name, it does not overwrite the existing Run entry: it creates a duplicate – notice this screenshot (taken after reloading Notepad++, so thatshortcuts.xml
will be updated) shows twoDebugFullCurrentPath
entries in the menu and in the XML:
In the state you are in now, I would recommend
- Run > Modify Shortcut / Delete Command
- Click on
Launch asm2bin
- Click Delete button and confirm in the next dialog
- If you created the
test
orDebugFullCurrentPath
commands that Alan and I recommended for testing, delete those as well. - Close this dialog
- Exit all instances of Notepad++ and restart
- Run > Run…
- program =
E:\CoCoDev\asm2bin.bat "$(FULL_CURRENT_PATH)"
- please notice the quote marks – they are really there. The full current path might contain spaces, and your batch file probably expects the path name as a single token, not multiple, so using quotes will make sure that the space is considered part of the filename.
- Save…, use your
Launch asm2bin
name, and whatever shortcut you desire - OK to save
- Now you can Cancel to exit dialog without running
- Check the Run menu to make sure
Launch asm2bin
has been re-created - Check Run > Modify Shortcut / Delete Command to make sure that
Launch asm2bin
doesn’t have a conflicting shortcut - Try running it, both from the Run > Launch asm2bin menu, and using your keyboard shortcut.
- If all is well, great! Otherwise continue
- Exit Notepad++ and restart.
- File > Open:
%AppData%\Notepad++\shortcuts.xml
, and theLaunch asm2bin
entry should look more like<Command name="Launch asm2bin" Ctrl="no" Alt="no" Shift="yes" Key="116">E:\CoCoDev\asm2bin.bat "$(FULL_CURRENT_PATH)"</Command>
Note, the detailed steps that I outlined have always worked for me in Notepad++, no bugs ever shown, for as long as I can remember.
If it still doesn’t, please show us what’s in your
shortcuts.xml
, and explain in your own words exactly what you did to get there. If you have a screen-recording app like ScreenToGif you can create an animated gif of the full process, and save/upload to imgur.com or similar, and link it like![](https://domain/path/file.gif)
(make sure you use imgur’s.gif
link, not the.gifv
or the one with no extension, which will not embed an image; if you’ve done it right, the preview window on the right will show your animation running while you’re editing your post)—
🛈 : Since you haven’t shown us your Debug Info, I am assuming you have a normal installation, where config files go in%AppData%\Notepad++
🔗. If you have cloud settings enabled, or are using a portable edition, theshortcuts.xml
file will be in a different location. But since you quoted from theshortcuts.xml
already, I am hoping you know this.