DOSKEY alias does not work in batch script (Windows 7)

别等时光非礼了梦想. 提交于 2019-12-04 14:26:53
Aacini

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 DOES work in batch files

  • Maybe your doskey string does not work

For example, try running this file, junk.bat :

doskey m=echo hi
cmd /k "echo try typing m now"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!