windows 打开 .bat 文件脚本后如何保持 cmd 运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15012344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:17:42  来源:igfitidea点击:

How to keep cmd running after opening a .bat file script

windowsbatch-filecmddirectory

提问by iDon'tKnow

Basically I have written a "script" in notepad and saved it as a .batfile. All it does is to change directory. Written like this:

基本上我在记事本中编写了一个“脚本”并将其保存为.bat文件。它所做的只是更改目录。写成这样:

cd C:\Users\Hello\Documents\Stuff 

It does change the directory, but i want to write more after that, within the cmd. Ex. choose a program to run. It seems simple, but i can't figure it out. I read about pause, but it just waits for a key and then closes down.

它确实改变了目录,但我想在那之后写更多,在cmd. 前任。选择要运行的程序。看起来很简单,但我想不通。我读过pause,但它只是等待一个键然后关闭。

回答by Endoro

Put cmd /kon the very last line of the script.

放在cmd /k脚本的最后一行。

回答by Radreaps

Try the following:

请尝试以下操作:

@echo off
Cmd /k

cmd /kstarts a new cmdinstance, /kstops terminating the console window after the commands are finished.

cmd /k启动一个新cmd实例,/k在命令完成后停止终止控制台窗口。

回答by bizzehdee

end your bat file with @pauseon its own line

@pause它自己的行结束你的 bat 文件