How do get my script file to console via Notepad++ external command?

百般思念 提交于 2019-12-20 01:42:08

问题


I am using Notepad++ for creating scripts and opening my active files from menu "Run" -> "Open current dir cmd". This works fine and the result is:

c:\scripts>

What I would like to have is the filename that I am working on currently so that I could try testing it right away. In my scripts I use parameters to define input and output files. Therefore the script shouldn't be run while opening, rather to have the script typed into console:

c:\scripts>edit_text.pl

I would then add manually the needed input and output files

c:\scripts>edit_text.pl input.txt output.txt

How do I make this possible in Notepad++ "Run" -feature?

Currently it is defined in shortcuts.xml as

cmd /K cd $(CURRENT_DIRECTORY)

I suspect that it would be something like this:

cmd /K cd $(CURRENT_DIRECTORY) $(FILE_NAME)

The problem is that this will "execute" the filename as well. I would like to have it waiting on the console for my actions.

Thanks in advance!


回答1:


The final code line would mean the CD and the script invocation being treated as one command. Separating then with && should help.

cmd /K cd $(CURRENT_DIRECTORY) && $(FILE_NAME)

However, that would do the CD then execute the command. I do not know of any way to enter a command but not execute it.

A poor solution would use the command below. You could copy and paste the echoed command then add in any parameters needed. Setting "Quick edit" mode on the window would make the copy and paste quicker.

cmd /K cd $(CURRENT_DIRECTORY) && ECHO $(FILE_NAME)

I have adopted a different approach for my own scripts although they do not have parameters that I need to enter. Edit the file (but not with Notepad++ as it overwrites the file just before it exits):

C:\Users\AdrianHHH\AppData\Roaming\Notepad++\shortcuts.xml

I have added some lines to the <UserDefinedCommands> section:

<NotepadPlus>
    ... unchanged
    <UserDefinedCommands>
        ... unchanged
        <Command name="Open containing folder" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_DIRECTORY)</Command>
        <Command name="Open current dir cmd" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /K cd /d $(CURRENT_DIRECTORY)</Command>
        <Command name="Run as command" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /C &quot;cd /d $(CURRENT_DIRECTORY) &amp;&amp; $(FULL_CURRENT_PATH)&quot;</Command>
        <Command name="Explorer with selection" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_WORD)</Command>
    </UserDefinedCommands>
    ... unchanged
</NotepadPlus>


来源:https://stackoverflow.com/questions/22174577/how-do-get-my-script-file-to-console-via-notepad-external-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!