April 22nd, 2003, 11:53 AM
Exit a C++ program
After I compile a program I run the program through a dos promt. I was wondering if there was a line of code to put into a C++ program that will exit out of dos when the program is done?
April 22nd, 2003, 12:51 PM
Why not wrapper it in a batch file?
Part of the problem is that if you call the DOS command, exit, from within your program via the system() function, it opens a new shell, so calling exit only closes the new shell, not the one your program is running in. I'm fairly sure that exec*() would do the same thing, but you could experiment with it.
April 22nd, 2003, 12:57 PM
am i correct in assuming that a .bat file is a pseudo shell script for windows? do u just create them as text files in notepad?
April 22nd, 2003, 01:07 PM
Yes. Or in VC++'s editor. Or in EDIT. Or in EDLIN (resurrected on Win2k for some odd reason). Or in your DOS port of vi.
However, bat files are nowhere near as powerful as shell scripts. You can do conditional jumps, test exit codes, handle command line parameters, set environment variables, call other bat files, but not much more. They're mainly used to store a commonly used sequence of commands for setting up your environment (eg, AUTOEXEC.BAT, my bat file for adding \dev-cpp\bin to my path). Before InstallShield and MSInstaller, we used to write INSTALL.BAT files to install software; create directories, copy files, change AUTOEXEC.BAT or CONFIG.SYS.