Link to home
Start Free TrialLog in
Avatar of APD Toronto
APD TorontoFlag for Canada

asked on

How to Prevent Batch File from closing

Hi Experts

I have the following simple batch file to open MySQL client, prompt me for my password and allow me to use it.  under Win 7 this works and the client window stays open, but under my Win 2003 the client window closes, how can I prevent this?

echo Entering MySQL Client

C:\

cd Program Files\MySQL\MySQL Server 5.5\bin

mysql -u root -p

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

You want it to stay open as a 'cmd' window like a terminal?
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of APD Toronto

ASKER

@Dave Baldwin

You want it to stay open as a 'cmd' window like a terminal?

Yes, exactly.
Try this.  You really don't need the second line.  But you probably need the quotes because the path has a space in it.
echo Entering MySQL Client

cd C:\

cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"

mysql -u root -p

Open in new window

Line #3 and #5 won't work if the batch file is run from a different drive - Line #3 will change the directory on the C: drive to \ but not change to that drive.  You either need
c:
cd "\program files.... etc."
or

cd /d "c:\program files ... etc."

Have you confirmed what happens if you open a cmd.exe window and type in the same commands?

Steve
This worked... but how/why?

I thought it was a server setting?
Almost like I'm invisible!
@dragon, what was your question... sorry?
I don't understandand still how it works, but it does
Wel I wasn't expecting that outcome, thankyou.

Agreed with Bill, the " " aren't needed but I tend to add them anyway to save confusion.

I can only assume you are maybe running this from a differemt driver perhaps which is why it failed.  If you want to see, try this.

@echo off
echo Driveis currently %cdF
dir mqsql*.*
pause
cd "\program files\etc.."
echo %cd%
dir msql*.*
pause

etc. using your full cd command.... this sort of debugging always useful, the echo %cd% will show you what drive and directory it thinks is current when you are at that point.  the dir command will look for anything called mysql it can run in that dir, and pause commands waits so you can see the issue.

if you take your original batch and add pause to the end, with echo %CD% before you will probably see it is not in the mqsql directory or other errors.

Steve
When I ran the batch file on my XP system (which is very similar to Server 2003), it did not like the formatting of some of the lines.  But it does run now without the quotes.