Link to home
Start Free TrialLog in
Avatar of alavan
alavan

asked on

Easy batch file question?

I want to enter a command in a batch file that closes the window when the program is done. Just like in a shortcut pif file that allows me to check the "Close on Exit" box. Is there a way to do this. "Exit" does not work.
Avatar of alamo
alamo

How are you running the batch file?
Use the "exit" command.
Use the "exit" command.  I just tested it and it works fine in both win95 and winnt.
Avatar of alavan

ASKER

If I create a batch file, leave it on the C: drive, go back to the desktop, open Windows Explorer and double-click the .bat file, the program runs and even indicates "Finished" on the Title Bar, but the MS-DOS box remains open. I want to close the box. The batch file runs nightly and when the PC is left unattended (most of the time) we end up with a bunch of MS-DOS boxes all over the screen.

I want to close the box.
I just did exactly that with a test file.  A batch file that ends in the command EXIT.  Click on it in explorer to open it, a window opens and the file runs, exit is then executed and the window closes.  I am wondering if your functions within it are ending abnormally and the batch file is not continuing to run to the exit line.  Try the following test: make a batch file that contains some easy simple command (like a dir) and then an exit on the last line, save it.  Try to run it as you outlined and see if it doesn't close the window.  If it doesn't, what version of windows are you running?  winnt 3.51, winnt 4.0, win95 .0, win95 A, win 95 B, etc...  If you are running win95 (the orginal version) with fixes, try putting on Service Pack 1.  
jruesch, I think if you take the "exit" out of your test file it will still close, the "exit" isn't necessary and doesn't make the window close. and as alavan originally said:
>"Exit" does not work.

Something else is happening here.
Alavan, when the window says "Finished" click on the icon in the upper left corner and select "properties".... somewhere there should be a "Close on Exit" checkbox which controls this behavior.
Avatar of alavan

ASKER

Thank you all for your suggestions. I just got back into the office. I'll have to revisit this on Monday. See you then.

Have a nice weekend.
Add "cls" (without the quotes) as the last line in the program or immediately befor the "exit".
s/befor/before :-)
Avatar of tuvi
It is easier to create a shortcut PIF file to the BAT file and choose close on exit. You don't have to create it, the first time the BAT file is run, Windows will automatically create it for you.
Avatar of alavan

ASKER

Alexo,  I'm not sure what your answer means. "s/befor/before" ?

Everyone, unfortunately my scheduling program won't let me execute either a shortcut or a pif file. When I enter the shortcut, it converts the name from .pif to .bat. Maybe there's no way to do this due to the fact that it's the window giving me issues and we're trying to close the window from DOS. Any more ideas.
My answer says: Add "cls" (without the quotes) as the last line in the program or immediately befor the "exit".

Then I niced a spelling mistake and suggested correcting it by substituting "before" for "befor".

Have you considered trying the "cls" suggestion before rejecting my answer?  It works, you know...
Avatar of alavan

ASKER

Alexo, the box still stays open even after cls. The screen clears, the exit command executes, then the box stays open.
Curiouser and curiouser...
What is your OS?  95 or NT?
Hi I just had a look to a bat file on my Win 95 system
clicked the right mouse button on it and select properties
a Property dialog opend with 6 tabs.
The second one is titeld with Program (it is the german version but I guess its same titled in english version)
There is near the bottom line a check box titeld (in german) 'Beim beenden schliessen' what means close window if program has finished if this box is checked my batch files will close on exit if not checked they do not close and only show inside the title bar that they are finished so checking these check box should close the window
I believe Norbert's suggestion will create a PIF file.
Avatar of alavan

ASKER

Norbert, the properties you are looking at are actually the .pif properties (that the Windows shell uses) of the .bat file. The batch file itself has no properties other than executing the DOS commands therein.

Alexo, I'm using Win95B. Maybe I need to look into a better scheduling program that'll let me execute Shortcuts and .pif's?
alavan, have you tried creating a PIF file for the batch file?  I may be wrong but I think Win95 will automatically consult the PIF file when the batch is run.

Another option is to set up a default PIF file (windows\_default.pif) to do what you want.

Some references:
  http://www.dejanews.com/getdoc.xp?AN=204069982
  http://www.dejanews.com/getdoc.xp?AN=236623973
  http://www.dejanews.com/getdoc.xp?AN=258897995
  http://www.dejanews.com/getdoc.xp?AN=258897749
  http://www.dejanews.com/getdoc.xp?AN=261758183
  http://www.dejanews.com/getdoc.xp?AN=292293661

I have the exact same problem with a VB program I wrote that creates and then runs a batch file.... I'm also running 95b... when the Batch file finishes does it print a message on your screen that says "your pop up program is now ready to run when you have finished press ctrl-c to return to windows".   I have tried executing a ctrl-c within the bat file but that occurs to soon.  This message seems to come up for me whenever i execute a batch file directly from windows bypassing the pif file.  Hopefully these guys can help, I know i'll be watching for their answer.
ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica 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 alavan

ASKER

It works Alexo! In order for the batch file to use the .pif file (shortcut) upon execution, the .pif file needs to be in the exact same directory as the .bat file. Once the .bat file is executed, it refers to the .pif file for property settings.

Creating the .pif (MS-DOS name) or shortcut (Win95 name) alone doesn't do it. I had to place it in the same directory.

It works. Took some clarification, but it works. Thank you all for your suggestions.