Prevent DOS Window from closing after executing Batch File

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?
Steve MeyerSystem Analyst and DeveloperAsked:
Who is Participating?
 
Steve KnightIT ConsultancyCommented:
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
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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
 
SunBowCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Steve MeyerSystem Analyst and DeveloperAuthor Commented:
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
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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
 
Steve MeyerSystem Analyst and DeveloperAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
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
 
Steve MeyerSystem Analyst and DeveloperAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
Is prepend a word ??!
0
 
Steve MeyerSystem Analyst and DeveloperAuthor Commented:
Prepend is a word in my dictionary.  I'l  try your recomendation.
0
 
Steve KnightIT ConsultancyCommented:
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
 
Steve MeyerSystem Analyst and DeveloperAuthor Commented:
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
 
Steve MeyerSystem Analyst and DeveloperAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
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
 
Steve MeyerSystem Analyst and DeveloperAuthor Commented:
Thanks Steve (dragon-it).  That was a big help and answers my questions.  Answers accepted.
0
 
Steve KnightIT ConsultancyCommented:
No problem, thanks for the points...

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.