#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    New York
    Posts
    5
    Rep Power
    0

    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?
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    Why not wrapper it in a batch file?

    E.g., MY_BAT.BAT
    Code:
    my_prog
    exit
    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.
  4. #3
  5. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    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?
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    Originally posted by infamous41md
    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?
    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.

IMN logo majestic logo threadwatch logo seochat tools logo