简体   繁体   English

Windows 命令提示自定义命令

[英]Windows command prompt custom commands

I am looking for a way to customise some of the Windows command prompt (cmd.exe) commands.我正在寻找一种方法来自定义一些 Windows 命令提示符 (cmd.exe) 命令。 I would like the new command to be called instead of the one defined by Windows to do almost the same thing except some minor customisations.我希望调用新命令而不是 Windows 定义的命令来做几乎相同的事情,除了一些小的定制。 An example could be with the pushd command print a message saying which directory is changing to.一个示例可能是使用 pushd 命令打印一条消息,说明正在更改到哪个目录。 This could be useful, for example, to have the output a.bat script parsed by another tool.这可能很有用,例如,让另一个工具解析 output a.bat 脚本。

As an example, pushd.bat would look like:例如,pushd.bat 看起来像:

@echo off
pushd %1
echo Entering directory `%cd%'

...but where should I put this so that it gets called instead of the internal command pushd? ...但是我应该把它放在哪里以便它被调用而不是内部命令 pushd?

You should not customize internal commands because some of these commands go all the way back to DOS and have hidden bugs and features that some tools might rely on and it is unlikely that you will implement them correctly.您不应该自定义内部命令,因为其中一些命令 go 一直回到 DOS,并且隐藏了一些工具可能依赖的错误和功能,您不太可能正确地实现它们。

You can add custom aliases with doskey .您可以使用doskey添加自定义别名。 These are better than batch files.这些比批处理文件更好。 They allow you to add certain mini scripts that help you in your daily command line usage.它们允许您添加某些迷你脚本,以帮助您进行日常命令行使用。 These can actually override the names of internal commands.这些实际上可以覆盖内部命令的名称。

doskey pushd=echo Entering $*^&pushd $*
pushd c:\Windows

You can add your doskey commands to HKCU\Software\Microsoft\Command Processor\AutoRun in the registry but you really need tobe careful if you use it to change existing commands.您可以将您的doskey命令添加到注册表中的HKCU\Software\Microsoft\Command Processor\AutoRun ,但如果您使用它来更改现有命令,您确实需要小心 I recommend that you invent new names for your commands.我建议您为命令发明新名称。

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

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