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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5181709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:08:02  来源:igfitidea点击:

Custom commands in windows Command Prompt

windowsterminal

提问by Prakhar

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

回答by Kaerber

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)。

回答by tenfour

You can use doskey. Try:

您可以使用doskey. 尝试:

doskey ntp=notepadpp.exe

doskey ntp=notepadpp.exe

and now you can do simply:

现在你可以简单地做:

ntp blah.txt

ntp blah.txt

回答by Learning2Code

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))

在该文件中放入以下代码行(或更改它以匹配您的 notepad++.exe 的路径))

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

@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 中。

回答by Coco

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 ntpif your file was named ntp.bat

通过写入文件名来执行它。例如,ntp如果您的文件名为 ntp.bat

Make sure that you restart the command line before trying your new super cool custom command.

在尝试新的超酷自定义命令之前,请确保重新启动命令行。

回答by SoliQuiD

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"

回答by John Edens

With doskey you can create a shortcut to load a list of these commands, Should solve your problems. set "start in" to pick where the shell opens.

使用 doskey,您可以创建一个快捷方式来加载这些命令的列表,应该可以解决您的问题。设置“开始”以选择外壳打开的位置。

dosmacro.lnk

域宏文件

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

macro.txt

宏.txt

    eg="C:/Program Files (x86)/EventGhost/EventGhost.exe" -event 
ing=ping 166.252.
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" 
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