emi-le
emi-le

Reputation: 796

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

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:

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

script2.bat:

mvn clean install

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.

Can anyone help?

Upvotes: 7

Views: 6343

Answers (2)

Jason
Jason

Reputation: 2132

  • 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"

Upvotes: -2

Aacini
Aacini

Reputation: 67216

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

Upvotes: 4

Related Questions