Solved How do I keep a cmd window open?

April 14, 2008 at 22:07:29
Specs: XP, 2 Gig

I run some programs such as MySQL from a cmd window. I'd like to automate running a cmd shell and then firing up MySQL, but leaving the cmd window open rather than having it close right away. If the cmd window closes, it shuts down the window that shows statuses as they change and the program ends. I tried using a .bat file but as soon as it runs the MySQL command, it closes the command window and the info is lost. Any ideas?

See More: How do I keep a cmd window open?

Report •


✔ Best Answer
April 16, 2008 at 16:15:50

my.bat
===================

cd c:\temp
cmd /k notepad


=====================================
If at first you don't succeed, you're about average.

M2



#1
April 15, 2008 at 01:45:46

That .bat file you created did your [close] the conversation?

What greater betrayal is there, to give pain where you owe love.


Report •

#2
April 15, 2008 at 02:56:04

With your batch file you could also put a new line with

pause

in it to keep the window open at any point during the running of the batch file. If you put pause right on the bottom line the cmd window will stay open (even when you close MySQL) prompting you to press any key to continue and / or close.


Report •

#3
April 15, 2008 at 07:46:26

Batch files aren't my specialty, however Mechanix2Go is one of the best (if not THE best) batchfilers I've ever met. You might want to message him here on computing.net about this request. I have no doubt he could help you build a batchfile that will do exactly what you want.

As I see it, you have a couple options. One would be as suggested by btklwl and using a 'pause' command. Another might be redirecting all output into a separate text file which you could then open/read at a later time.

As a 3'd option you could just open a command prompt window and run the command manually. However, this doesn't allow for automation.


Report •

Related Solutions

#4
April 16, 2008 at 13:59:52

If the BAT is running an executable, it should wait until the exe is done. If it does not, something is seriously wrong. Is your BAT running another BAT?


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
April 16, 2008 at 15:48:28

You are right, it turned out that my .bat file statements ran in to an error, displayed it, and then stopped which caused the window to close. this happened so fast that I couldn't see what was causing it. Not until I put a pause at the end of the bat file and then I could see it. Once fixed, the cmd window would stay open until the program was stopped (by hitting Ctrl-C). Then it would immediately close.

Even still though, what would it take to double click a bat file that causes a cmd window to open, launch an application, display some results, then end WITHOUT the cmd window closing? Just leave the results in the cmd window and keep it displayed. Any way to do it without using Pause?

thanks


Report •

#6
April 16, 2008 at 16:15:50
✔ Best Answer

my.bat
===================

cd c:\temp
cmd /k notepad


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#7
April 17, 2008 at 13:22:26

This appears to work well and should do the trick.

One question though - let's say I'm in a "test" directory on the d drive and I place the bat file in this test directory. when the bat file is executed, it will work but the cmd window will still display its location as the d:\test directory rather than the c:\temp directory. Is there a way to have the cmd window show up in the temp directory instead of the test directory?

thanks,
steve


Report •

#8
April 18, 2008 at 04:33:57

cd /d d:\test
cmd /k notepad


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#9
April 18, 2008 at 09:32:40

Thanks for the info. Is there a book or something out there with all these commands or is it a good knowledge of the old DOS operating systems that helps?

thanks again,

steve


Report •

#10
April 18, 2008 at 11:17:25

You can sometimes get help with CMD /?

As ever, windows 'help' often ain't much help.

For plain DOS [not NTVDM] 'DOS Power Tools' from Ziff-Davis, ca 1986.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#11
April 21, 2008 at 16:02:12

Why are you not starting Mysql as a service? Then you would not need to 'start' it from a command prompt.

Start -> Run -> CMD.EXE opens a permanently appearing command prompt. It won't go away until you type 'exit' or click that familiar X in the right corner.

As for a 'book' have you actually looked at a computer section in a bookstore or at Amazon? Wow billions and billions.

Microsoft even keeps a reference library on it's technet site (google is good for finding this), but I would think you should get a copy of 'XP Administrators Quick Guide', its small, cheap and very handy.

Good luck,

J.
j e r u v y a t y a h o o d o t c o m


Report •

#12
April 21, 2008 at 17:02:00

I'm not simply after a book about the operating systems with a simple command set, I'm after a book about command line commands that can be used for creating batch files.
Do you know the names of maybe one or two books that covers everything there is to know about a command line process and associated commands? If so, what are the names of the books? That's all I'm after is the names. Saves the hassle of researching online or wandering through a bookstore perusing books to see if they have what I'm after. That's why I asked the question.

I spent way too much time searching on Microsoft's site for this info, only to discover this site, which obviously contains questions from many others that lucky for us, Mechanix2Go can answer.

I'm not interested in manually launching a command window. It's a lot easier to create a mechanized solution with batch files that will meet our needs. Manually spawning a command process was never part of the problem other than us wanting to avoid it by using batch files.

Regarding MySQL, yes, I realize it's started as a service. I used it as an example for several things we do where we would like the cmd window to stay open once a process stops, but was launched by a bat file. MySQL, Ruby, Rails, etc., are just some of the apps we use where we want to use batch files for ease of use.


Report •

#13
April 21, 2008 at 21:48:36

I'm glad you came here looking for answers, but when it comes to books wouldn't it make more sense to go look at them and maybe read a bit to see 'if you like them'? I'll just take a stab that the books I like are probably not going to be on most folks lists and that ok.

As for spending a lot of time on Microsoft's site, well that can be a good thing. Sure searching can be painful, but that's what search engines are for. Besides there is an incredible wealth of information on microsofts site so forgive me if I don't understand your avoidance. Especially when it provides the best resource of what you seek.

I'd recommend reviewing technet and 'how to search the knowledge base' articles for more details. It's tough but in the end you'll wonder why you spent so much time elsewhere getting only part of the story.

If your going to be playing with windows scripts, why not migrate to the 21st century and get the real power tool, powershell?

P.S. I offer these as suggestions, if you don't like them cool. Enjoy anyways!

J.
j e r u v y a t y a h o o d o t c o m


Report •

#14
April 21, 2008 at 21:56:55

Thanks, perhaps my posting sounded a bit harsh which I appologize for. I was in a hurry and could've done better. I was trying to avoid searching for info that someone might have readily on hand otherwise I could've spent the time searching. way too little time and too much to get done so searching was something I hoped I wouldn't have to do. thanks for the powershell hint though. I'll check it out.
steve

Report •


Ask Question