Solved

How to Prevent Batch File from closing

Posted on 2014-04-14
12
543 Views
Last Modified: 2014-04-15
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

0
Comment
Question by:APD_Toronto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
12 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40000299
You want it to stay open as a 'cmd' window like a terminal?
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 40000359
Could it just be you are running it from the wrong place because it is a 32 bit program on a 64 bit Windows 7 and installed in a different directory?  Try one of these:

@echo off
echo Entering MySQL Client
cd /d "c:\Program Files (x86)\MySQL\MySQL Server 5.5\bin"
mysql -u root -p

Open in new window


or

@echo off
echo Entering MySQL Client
cd /d "c:\Program Files\MySQL\MySQL Server 5.5\bin"
mysql -u root -p

Steve
0
 

Author Comment

by:APD_Toronto
ID: 40000453
@Dave Baldwin

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

Yes, exactly.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40000470
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

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40000526
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
0
 

Author Comment

by:APD_Toronto
ID: 40000530
This worked... but how/why?

I thought it was a server setting?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40000533
Almost like I'm invisible!
0
 

Author Comment

by:APD_Toronto
ID: 40000561
@dragon, what was your question... sorry?
0
 

Author Closing Comment

by:APD_Toronto
ID: 40000567
I don't understandand still how it works, but it does
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40000861
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
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40000990
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.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question