简体   繁体   English

Windows命令提示符中的自定义命令

[英]Custom commands in windows Command Prompt

How do I write a custom command to open files with Notepad++ text editor in Windows Command prompt. 如何编写自定义命令以在Windows命令提示符下使用Notepad ++文本编辑器打开文件。

For eg. 例如。

C:\Sites>ntp abc.txt

opens the file abc.txt in Notepad++ 在Notepad ++中打开文件abc.txt

Create a batch file containing this line 创建包含此行的批处理文件

@START c:\Program Files\Notepad++\notepad++.exe "%1"

and put it into some directory that is in your PATH list (or, alternatively, add a directory with a .bat file to PATH). 并将其放入PATH列表中的某个目录中(或者,将带有.bat文件的目录添加到PATH中)。

You can use doskey . 你可以使用doskey Try: 尝试:

doskey ntp=notepadpp.exe

and now you can do simply: 现在你可以做到:

ntp blah.txt

Create a .bat file and save it as npt.bat 创建一个.bat文件并将其另存为npt.bat

In that file put the following line of code (or change it to match the path to your notepad++.exe)) 在该文件中放入以下代码行(或更改它以匹配记事本++。exe的路径))

@START c:\\"Program Files (x86)"\\Notepad++\\notepad++.exe "%1"

Note that you need quotation marks around any parts of the path with spaces in it. 请注意,您需要在路径的任何部分周围加上带空格的引号。

Now place it in whatever directory you like and add the directory to PATH in your User variables. 现在将它放在您喜欢的任何目录中,并将目录添加到用户变量中的PATH。

You can also create a bat file which does what you wish (mentioned in other answers here), then put it in C:\\Windows\\System32. 您还可以创建一个bat文件,它可以执行您想要的操作(在此处的其他答案中提到),然后将其放在C:\\ Windows \\ System32中。

Execute it by writing the name of the file. 通过写入文件名来执行它。 For example ntp if your file was named ntp.bat 例如,如果您的文件名为ntp.bat,则为ntp

Make sure that you restart the command line before trying your new super cool custom command. 在尝试新的超酷自定义命令之前,请确保重新启动命令行。

In addition to the answer of @Kaerber 除了@Kaerber的答案

This works for me 这适合我

@START c:\"Program Files"\Notepad++\notepad++.exe "%1"

While this doesn't work (and just opens the explorer) 虽然这不起作用(只是打开资源管理器)

@START "c:\Program Files\Notepad++\notepad++.exe" "%1"

With doskey you can create a shortcut to load a list of these commands, Should solve your problems. 使用doskey,您可以创建一个快捷方式来加载这些命令的列表,应该解决您的问题。 set "start in" to pick where the shell opens. 设置“开始”以选择shell打开的位置。

dosmacro.lnk dosmacro.lnk

C:\Windows\System32\cmd.exe /k Doskey /macrofile="C:\Users\John.Edens\Documents\Programming\Scripts\_Main\Doskey\macros.txt"

macro.txt macro.txt

    eg="C:/Program Files (x86)/EventGhost/EventGhost.exe" -event $1
ing=ping 166.252.$1
amts.audi=ping 166.252.**.**
amts.sfa=ping 166.252.***.***
amts.ers=ping 166.252.***.***
amts.wbt=ping 166.252.***.****
amts.rej=ping 166.252.***.**
++=@START "C:\Program Files\Notepad++\notepad++.exe" $1
rain="C:/Program Files (x86)/EventGhost/EventGhost.exe" -event rain
holly="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --new-window https://www.messenger.com/t/hol*********
kill="C:\Users\John.Edens\Documents\Programming\Scripts\_Main\Killghost.vbs"
undock=="C:/Program Files (x86)/EventGhost/EventGhost.exe" -event undock
dosadd="C:/Program Files (x86)/EventGhost/EventGhost.exe" -event dosadd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM