Keep CMD open after BAT file executes

2019-01-10 06:28发布

I have a bat file like this:

ipconfig

That will print out the ip info to the screen, but before the user can read that info CMD closes it's self.

I believe that CMD assumes the script has finished, so it closes.

How do I keep CMD open after the script is finished? Thanks!

9条回答
男人必须洒脱
2楼-- · 2019-01-10 07:03

just Add @pause at the end

Example :

@echo off
ipconfig
@pause

or u can also use :

cmd /k ipconfig
查看更多
Root(大扎)
3楼-- · 2019-01-10 07:04

Put pause at the end of your .BAT file.

查看更多
爷、活的狠高调
4楼-- · 2019-01-10 07:04

In Windows add '& Pause' to the end of your command in the file.

查看更多
beautiful°
5楼-- · 2019-01-10 07:08

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.

Example :

cmd /k gradlew cleanEclipse
查看更多
狗以群分
6楼-- · 2019-01-10 07:10

If you are starting the script within the command line, then add exit /b to keep CMD opened

查看更多
我命由我不由天
7楼-- · 2019-01-10 07:14

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!

For instance I was trying to run java command...

cmd /k java myPackage.myClass

It kept the window open so I could see my "System.out.println()" messages.

I hope this clarification saves someone the approximately 3.5 minutes it took me to figure it out.

查看更多
登录 后发表回答