简体   繁体   English

批处理脚本以打开命令提示符,但不执行命令

[英]Batch script to open command prompt but not execute the command

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. 仅当我手动按Enter键时,它才应执行。 eg., I created the below .bat file: 例如,我创建了以下.bat文件:

test.bat 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. 现在的问题是它打开了命令窗口并列出了目录内容,而我只希望dir命令停留在此位置,并且在我手动按Enter键之前不列出目录内容。 Pls suggest if there is a way to do that 请建议是否有办法

I copied the accepted answer at How can I run cmd from batch file and add text to line without executing? 我在如何从批处理文件运行cmd并将文本添加到行而不执行的情况下复制了可接受的答案 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. 给定链接上的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM