如何在Windows命令提示符下查找文件源?
来自linux shell,我习惯于将文件导入当前环境。如何在Windows如何在Windows命令提示符下查找文件源?,windows,cmd,Windows,Cmd,来自linux shell,我习惯于将文件导入当前环境。如何在Windowscmd命令提示符下执行此操作 e、 g.在linux中,我可以为长而复杂的命令创建别名: alias shortcut="some super long command with lots of --options and arguments etc" alias another="some other super long command with lots of --options and arguments etc
cmd
命令提示符下执行此操作
e、 g.在linux中,我可以为长而复杂的命令创建别名:
alias shortcut="some super long command with lots of --options and arguments etc"
alias another="some other super long command with lots of --options and arguments etc"
alias again="yet another super long command with lots of --options and arguments etc"
然后我可以将它保存到一个文件中,只需源别名.bash
,甚至在启动shell时自动加载它,例如在.bashrc
或文件中使用时
我知道我可以在运行时在cmd
提示符下使用doskey
doskey shortcut="some super long command with lots of --options and arguments etc"
但是如何将所有这些doskey
条目保存到主文件中,以便加载到当前环境中呢?更好的是,启动cmd
提示符时,如何自动加载它们?回答如下:
您可以将命令加载到bat中,然后在登录时通过在注册表中创建指向批处理文件的自动运行条目将其运行到命令处理器中。您可以向注册表添加自动运行条目,以便在cmd
启动时自动运行.cmd文件
创建一个文件C:\Users\Jeff\autorun.cmd
,并向其中添加doskey命令,如下所示:
@echo off
doskey shortcut="some super long command with lots of --options and arguments etc"
doskey another="some other super long command with lots of --options and arguments etc"
doskey again="yet another super long command with lots of --options and arguments etc"
然后,在注册表中编辑HKEY\U LOCAL\U MACHINE\Software\Microsoft\Command Processor
,以包含以下内容:
AutoRun=C:\Users\Jeff\AutoRun.cmd
根据。提供的信息,尝试拨打电话
command@YuJiaao你的意思是像调用filename.ext
?因为这告诉我,filename.ext不能被识别为内部或外部命令、可操作程序或批处理文件。
@yujiao啊,是的,它可以工作,但文件名必须有扩展名.bat
谢谢!现在,在启动提示符时,我如何自动启动它?与bash别名相比,doskey.exe设置的Windows控制台别名令人失望。它们在控制台主机进程conhost.exe中工作,该进程替换在行首匹配且仅在行首匹配的别名。从控制台读取的应用程序(如cmd.exe)甚至不知道别名是否存在。它只读取别名已被替换的行。因此,您无法通过管道连接到CMD中的别名,而且由于它们是控制台的一种生物,因此doskey.exe设置的别名不能在批处理脚本中使用。您可以使用/macrofile=filename
参数为命名节(如“[CMD.exe]”和“[python.exe]”中的多个可执行文件安装控制台别名。此外,它应该检查并设置一个环境变量,以防止重新加载别名。每次CMD在没有/D选项的情况下执行时,它都会执行AutoRun键,因此请记住,C运行时不会将/D用于system
命令,其他库(如Python的subprocess)也不会使用shell=True
。在为管道运行自身的另一个实例时,至少CMD本身使用/D。