I have a bat file like this:
我有一个这样的bat文件:
ipconfig
That will print out the ip info to the screen, but before the user can read that info CMD closes it's self.
这将把ip信息打印到屏幕上,但是在用户读取信息之前,CMD关闭它自己。
I believe that CMD assumes the script has finished, so it closes.
我相信CMD假设脚本已经完成,所以它关闭了。
How do I keep CMD open after the script is finished? Thanks!
如何在脚本完成后保持CMD打开?谢谢!
9 个解决方案
#1
95
Depending on how you are running the command, you can put /k
after cmd
to keep the window open.
根据您运行该命令的方式,您可以在cmd之后放置/k以保持窗口打开。
cmd /k my_script.bat
#2
137
Put pause
at the end of your .BAT file.
在. bat文件的末尾暂停。
#3
31
just Add @pause
at the end
在末尾添加@pause。
Example :
例子:
@echo off
ipconfig
@pause
or u can also use :
或者你也可以使用:
cmd /k ipconfig
#4
16
Just to clarify something that took me a little bit to understand after reading these responses...
只是为了澄清一些在阅读这些回复后我有点理解的东西……
You have to type (literally) "cmd /k" followed by your command. I, at first, thought that "cmd" was to be replaced by your command. Not the case!
你必须打字(按字面意思)“cmd /k”后面跟着你的命令。起初,我认为“cmd”应该由你的命令来代替。不是这样的!
For instance I was trying to run java command...
例如,我试图运行java命令…
cmd /k java myPackage.myClass
It kept the window open so I could see my "System.out.println()" messages.
它保持窗口打开,这样我就可以看到我的“System.out.println()”消息。
I hope this clarification saves someone the approximately 3.5 minutes it took me to figure it out.
我希望这个澄清能拯救一个人大约3。5分钟的时间让我把它弄清楚。
#5
3
Adding pause
in (Windows 7) to the end did not work for me
but adding the cmd /k
in front of my command did work.
在(Windows 7)中添加暂停对我来说没有效果,但是在我的命令前面添加cmd /k确实有效。
Example :
例子:
cmd /k gradlew cleanEclipse
#6
1
start cmd /k
did the magic for me. I actually used it for preparing cordova phonegap app it runs the command, shows the result and waits for the user to close it. Below is the simple example
开始cmd /k为我做了魔术。我实际上使用它来准备cordova phonegap应用程序,它运行该命令,显示结果并等待用户关闭它。下面是一个简单的例子。
start cmd /k echo Hello, World!
What I did use in my case
我在我的案例中使用了什么!
start cmd /k cordova prepare
Update
更新
You could even have a title for this by using
你甚至可以用它来命名。
start "My Title" echo Hello, World!
开始“我的标题”回声你好,世界!
#7
0
javac -d C:\xxx\lib\ -classpath C:\xxx\lib\ *.java
cmd cd C:\xxx\yourbat.bat
the second command make your cmd window not be closed. The important thing is you still able to input new command
第二个命令使您的cmd窗口不关闭。重要的是您仍然能够输入新的命令。
#8
0
If you are starting the script within the command line, then add exit /b
to keep CMD opened
如果在命令行中启动脚本,则添加exit /b以保持CMD打开。
#9
-1
In Windows add '& Pause' to the end of your command in the file.
在Windows中,在文件末尾添加“&暂停”命令。
#1
95
Depending on how you are running the command, you can put /k
after cmd
to keep the window open.
根据您运行该命令的方式,您可以在cmd之后放置/k以保持窗口打开。
cmd /k my_script.bat
#2
137
Put pause
at the end of your .BAT file.
在. bat文件的末尾暂停。
#3
31
just Add @pause
at the end
在末尾添加@pause。
Example :
例子:
@echo off
ipconfig
@pause
or u can also use :
或者你也可以使用:
cmd /k ipconfig
#4
16
Just to clarify something that took me a little bit to understand after reading these responses...
只是为了澄清一些在阅读这些回复后我有点理解的东西……
You have to type (literally) "cmd /k" followed by your command. I, at first, thought that "cmd" was to be replaced by your command. Not the case!
你必须打字(按字面意思)“cmd /k”后面跟着你的命令。起初,我认为“cmd”应该由你的命令来代替。不是这样的!
For instance I was trying to run java command...
例如,我试图运行java命令…
cmd /k java myPackage.myClass
It kept the window open so I could see my "System.out.println()" messages.
它保持窗口打开,这样我就可以看到我的“System.out.println()”消息。
I hope this clarification saves someone the approximately 3.5 minutes it took me to figure it out.
我希望这个澄清能拯救一个人大约3。5分钟的时间让我把它弄清楚。
#5
3
Adding pause
in (Windows 7) to the end did not work for me
but adding the cmd /k
in front of my command did work.
在(Windows 7)中添加暂停对我来说没有效果,但是在我的命令前面添加cmd /k确实有效。
Example :
例子:
cmd /k gradlew cleanEclipse
#6
1
start cmd /k
did the magic for me. I actually used it for preparing cordova phonegap app it runs the command, shows the result and waits for the user to close it. Below is the simple example
开始cmd /k为我做了魔术。我实际上使用它来准备cordova phonegap应用程序,它运行该命令,显示结果并等待用户关闭它。下面是一个简单的例子。
start cmd /k echo Hello, World!
What I did use in my case
我在我的案例中使用了什么!
start cmd /k cordova prepare
Update
更新
You could even have a title for this by using
你甚至可以用它来命名。
start "My Title" echo Hello, World!
开始“我的标题”回声你好,世界!
#7
0
javac -d C:\xxx\lib\ -classpath C:\xxx\lib\ *.java
cmd cd C:\xxx\yourbat.bat
the second command make your cmd window not be closed. The important thing is you still able to input new command
第二个命令使您的cmd窗口不关闭。重要的是您仍然能够输入新的命令。
#8
0
If you are starting the script within the command line, then add exit /b
to keep CMD opened
如果在命令行中启动脚本,则添加exit /b以保持CMD打开。
#9
-1
In Windows add '& Pause' to the end of your command in the file.
在Windows中,在文件末尾添加“&暂停”命令。