DOSKEY别名在批处理脚本中不起作用(Windows 7) [英] DOSKEY alias does not work in batch script (Windows 7)

查看:277
本文介绍了DOSKEY别名在批处理脚本中不起作用(Windows 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过批处理脚本( script1.bat )添加了DOSKEY别名,并尝试在另一个批处理脚本中调用它.它不起作用.

I added a DOSKEY alias via batch script (script1.bat) and try to call it in another batch script. It doesn't work.

script1.bat:

script1.bat:

set USER_SETTINGS=%DRIVE%\programme\settings.xml
DOSKEY mvn=mvn --settings %USER_SETTINGS% -X $*

script2.bat:

script2.bat:

mvn clean install

当我从控制台调用mvn clean install时,它可以工作.调试输出即将推出.当我从同一控制台调用 script2.bat 时,没有调试输出输出.

When I call mvn clean install from the console, it works. The debug output is forthcoming. When I call script2.bat from the same console, no debug output is coming.

任何人都可以帮忙吗?

推荐答案

如果通过doskey /?显示doskey帮助,则会得到以下内容:在DOS提示符下调用和编辑命令,并创建宏" .批处理文件在DOS提示符下不是 :DOS KEY 命令可与按键作为输入的键一起使用,例如箭头或F7键.

If you show the doskey help via doskey /? you get something like: "Recall and edit commands at the DOS prompt, and create macros". A Batch file is not the DOS prompt: the DOSKEY command works with keys pressed as input, like arrows or F7 keys.

由于这个原因,下一个代码应该可以工作:

For this reason, the next code should work:

script2.bat :

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem Send the keys with the DOSKEY macro name:
%SendKeys% "mvn clean install{ENTER}"

goto :EOF


@end


// JScript section


WshShell.SendKeys(WScript.CreateObject("WScript.Shell").Arguments(0));

更多详细信息,请参见使用批处理文件按键盘键

Further details at Press Keyboard keys using a batch file

这篇关于DOSKEY别名在批处理脚本中不起作用(Windows 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆