且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DOSKEY别名在批处理脚本中不起作用(Windows 7)

更新时间:2022-12-18 08:41:28

如果通过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