[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Prevent DOS Window from closing after executing Batch File

Posted on 2006-04-27
16
Medium Priority
?
2,617 Views
Last Modified: 2008-01-09
I am still supporting several Clipper Applications that I wrote ten years ago.  The development environment is stricly DOS; I have to work with the compilers and linkers in a DOS window.  This requires execution of a fairly sophisicated DOS Batch file (50+ lines of DOS commands) that are designed to setup up the DOS environment so that I can work with the compiler and linker in a particular directory.  I created a shortcut to execute the batch file, but after it executes, the window closes.  In Windows 98, the window automatically stayed open unless you "checked" the "Close on Exit" box in the properties of the shortcut.  But in XP there is no such box.  Adding "cmd" to the end of the batch file doesn't work.   I coplied the W98 shortcut over to the XP machine, but although the shortcut opens the DOS session (and leaves it open), it won't execute the specified Batch File.  Any suggestions?
0
Comment
Question by:meyco
  • 7
  • 6
  • 2
  • +1
16 Comments
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 16557550
Add a PAUSE line as the last line of code in the batch file.  It will leave it open until you press a key.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 16558695
I agree.

I've used other methods, whether programs, commands, switches, or loops, but I think that in general, using the Pause command is the quickest path to results desired.

A part of answer could depend on whether you want the dos window open for entry of further commands, and whether you are nesting batch calls. A part of answer could be whether you want to run code from a file clicked on in explorer, or automatically (in the background?) or from a menu or a shortcut. Each can have advantages and disadvantages.

But for the question raised, the Pause command should get you the chance to review the work before moving on.

As an alternative, if you/I are going to do a lot of work in Dos windows, I just make myself a couple of shortcuts for CMD, that'll get me quick to a desired subdirectory as it opens. Now when batch files end, they'll more often end at the dos prompt, where I can do the forms of debugging that dos is good at more effectively.
0
 

Author Comment

by:meyco
ID: 16558869
The purpose of my batch file is to setup the DOS development environment (settings etc.), so that I can then proceed with typing additional dos commands to edit, complile, link and test the applicaton.  Pause closes the window and erases the environment settings.
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 16558891
Have you considered modifying the Autoexec.NT file to include the needed variables/settings.  And/or adding the environment variables via the System Control panel?

0
 

Author Comment

by:meyco
ID: 16558929
Leew,

That's a possibility, but I would need a different Autoexec.NT file for each application.  Presently, I simply go to the command prompt (Run->Cmd), and simply execute the batch file to setup the environment.   No big deal, but it worked in W98 and it worked really nice.  Why does MS always have to screw up a good thing?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16559927
Are you sure adding cmd.exe as the last line doesn't work?  It should start a new instance of the command interpreter and sit there at the c:> prompt for you.... it works for me?

Steve
0
 

Author Comment

by:meyco
ID: 16561487
When I execute cmd.exe as the last line in my batch file, I get a DOS error message that reads:      'cmd.exe' is not recognized as an internal or external command, operable program or batch file.
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 16561523
Try %compsec% instead.  It would appear that cmd.exe is not on your path -- I guess you are changing the path, perhaps rather than amending it you should prepend to it, i.e.

set path = c:\mypath ; %path%

echo %comspec% to make sure it is set right

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16561534
Is prepend a word ??!
0
 

Author Comment

by:meyco
ID: 16561593
Prepend is a word in my dictionary.  I'l  try your recomendation.
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 2000 total points
ID: 16561629
BTW that doesn't look to clear now I look back, I mean as well as potentially fixing your path changes you could just add a blank line with %compsec% and it will pickup the contents of that environment variable which should be something like c:\winnt\system32\cmd.exe but let me know how it goes!

Steve
0
 

Author Comment

by:meyco
ID: 16561764
I picked up on your initial suggestion and used: c:\windows\system32\cmd.exe instead of comspec.  I forgot that I modified the paths in my script and omitted the windows directories.  I should realized that when I got the error message.  In any case, your suggestion worked.  I don't know why I thought a second instance of cmd would close my current sesssion and open another one; I figured I would lose my envionment settings in the second instance.  Thanks.

On the subject of usng my old shortcuts from W98, here's the problem.  The properties are setup as follows:

Cmd Line: cmd.exe
Working: M:\
Batch File: c:\csetup.bat (the batch file from above)
Shortcut Key: None
Run: Normal Window
Close on Exit: [checked]

When executed, a DOS window is opened and the working directory is set to M:\, which is fine, but the batch file doesn't execute.  Apprently this feature is no longer allowed in XP.  Am I correct?  Some my old DOS applications require the old shortcuts (I assume these are pif files).  Any suggestions?
0
 

Author Comment

by:meyco
ID: 16561783
On the issue of the cmd.exe, is it your understanding that the second DOS instance inherits all the settings from the first one?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16562528
It should do as far as I know -- I often started cmd.exe shells (well OK command.com) from within old DOS programs and they always inherit the parent environment.  You could always start command.com instead if you fancy instead!

Your existing shortcuts won't work correctly because as you say this feature doesn't seem to work any more but you should be able to do it still, just create a new shortcut directly to the bat file and set the properties - working directory etc. and you'll have to add %comspec% onto the end of the BAT file if you want it to stay open and usable.  PIF files are still there under the hood with the option to run batch files but as you say they don't seem to work.The defaults are picked up from c:\winnt\_default.pif afaik.

You can always go into the advanced properties of a PIF file shortcut and run the batch file in place of autoexec.nt -- copy _default.pif and amend if you need a new one.

regards

Steve
0
 

Author Comment

by:meyco
ID: 16563031
Thanks Steve (dragon-it).  That was a big help and answers my questions.  Answers accepted.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16563096
No problem, thanks for the points...

Steve
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

834 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