2

Can anyone pls suggest me how to create a batch file that would open up the command window but just type the command I have specified. It should get executed only when I hit enter manually. eg., I created the below .bat file:

test.bat

cmd.exe /K "cd D:\Code_Home && D: && cls && dir"

Now the problem is that it opens up the command window and lists the directory contents, whereas I just want the dir command to stay there and not list me the directory contents until I manually hit enter. Pls suggest if there is a way to do that

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
user1703096
  • 115
  • 6

1 Answers1

0

I copied the accepted answer at How can I run cmd from batch file and add text to line without executing? and slightly adjust it in order to solve this question:

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

@echo off
rem Enter the prefill value in the keyboard buffer
CScript //nologo //E:JScript "%~F0" "cd D:\Code_Home & D: & cls & dir"
cmd.exe
goto :EOF

@end

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

Further details at the given link.

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108