Terminating program with "exit( )"

Discussion in 'C Programming' started by ern, Mar 23, 2006.

  1. ern

    ern Guest

    Right now I'm using exit(0) to [attemp to] terminate my program. My
    program is a console .exe application. After the "exit(0)" line of
    code is encountered, the console application waits for an enter press,
    before terminating. I want it to terminate completely without having
    to press enter manually. Anybody know what I might be missing here ?
     
    ern, Mar 23, 2006
    #1
    1. Advertising

  2. ern

    Default User Guest

    ern wrote:

    > Right now I'm using exit(0) to [attemp to] terminate my program. My
    > program is a console .exe application. After the "exit(0)" line of
    > code is encountered, the console application waits for an enter press,
    > before terminating. I want it to terminate completely without having
    > to press enter manually. Anybody know what I might be missing here ?


    Are you running this from an IDE, like Visual Studio or some such
    thing?


    Brian

    --
    Please quote enough of the previous message for context. To do so from
    Google, click "show options" and use the Reply shown in the expanded
    header.
     
    Default User, Mar 23, 2006
    #2
    1. Advertising

  3. ern

    pemo Guest

    ern wrote:
    > Right now I'm using exit(0) to [attemp to] terminate my program. My
    > program is a console .exe application. After the "exit(0)" line of
    > code is encountered, the console application waits for an enter press,
    > before terminating. I want it to terminate completely without having
    > to press enter manually. Anybody know what I might be missing here ?


    Post a working sample of the code - then we might be able to help.

    --
    ==============
    *Not a pedant*
    ==============
     
    pemo, Mar 23, 2006
    #3
  4. ern

    ern Guest

    Default User wrote:
    > ern wrote:
    >
    > > Right now I'm using exit(0) to [attemp to] terminate my program. My
    > > program is a console .exe application. After the "exit(0)" line of
    > > code is encountered, the console application waits for an enter press,
    > > before terminating. I want it to terminate completely without having
    > > to press enter manually. Anybody know what I might be missing here ?

    >
    > Are you running this from an IDE, like Visual Studio or some such
    > thing?
    >
    >
    > Brian
    >
    > --
    > Please quote enough of the previous message for context. To do so from
    > Google, click "show options" and use the Reply shown in the expanded
    > header.


    Visual C++ IDE
     
    ern, Mar 23, 2006
    #4
  5. ern

    ern Guest

    pemo wrote:
    > ern wrote:
    > > Right now I'm using exit(0) to [attemp to] terminate my program. My
    > > program is a console .exe application. After the "exit(0)" line of
    > > code is encountered, the console application waits for an enter press,
    > > before terminating. I want it to terminate completely without having
    > > to press enter manually. Anybody know what I might be missing here ?

    >
    > Post a working sample of the code - then we might be able to help.
    >
    > --
    > ==============
    > *Not a pedant*
    > ==============


    if(result == EXIT_PROGRAM){
    printf("Exit script command detected.\n");
    exit(0); //Thought this line would exit, but it doesn't
    // It requires that you press enter after for console
    termination.
    }
     
    ern, Mar 23, 2006
    #5
  6. ern

    Default User Guest

    ern wrote:

    >
    > Default User wrote:


    > > Are you running this from an IDE, like Visual Studio or some such
    > > thing?


    > Visual C++ IDE


    There you go. That's not a language thing, it's just the IDE. People
    don't want that window disappearing, because you can't see the output.
    You have to ask on a Visual Studion newsgroup of some sort whether that
    can be changed. There's nothing C can do.



    Brian
     
    Default User, Mar 23, 2006
    #6
  7. ern

    Default User Guest

    ern wrote:

    >
    > pemo wrote:


    > > Post a working sample of the code - then we might be able to help.


    > if(result == EXIT_PROGRAM){
    > printf("Exit script command detected.\n");
    > exit(0); //Thought this line would exit, but it doesn't
    > // It requires that you press enter after for console
    > termination.
    > }


    As I said elsewhere, it's the IDE. Try running that from a command you
    opened, you'll see the expected behavior.



    Brian
     
    Default User, Mar 23, 2006
    #7
  8. ern

    Ian Collins Guest

    ern wrote:
    > pemo wrote:
    >
    >>ern wrote:
    >>
    >>>Right now I'm using exit(0) to [attemp to] terminate my program. My
    >>>program is a console .exe application. After the "exit(0)" line of
    >>>code is encountered, the console application waits for an enter press,
    >>>before terminating. I want it to terminate completely without having
    >>>to press enter manually. Anybody know what I might be missing here ?

    >>
    >>Post a working sample of the code - then we might be able to help.
    >>
    >>--
    >>==============
    >>*Not a pedant*
    >>==============

    >
    >
    > if(result == EXIT_PROGRAM){
    > printf("Exit script command detected.\n");
    > exit(0); //Thought this line would exit, but it doesn't
    > // It requires that you press enter after for console
    > termination.
    > }
    >

    Run the application outside of your IDE.

    --
    Ian Collins.
     
    Ian Collins, Mar 23, 2006
    #8
  9. ern

    Flash Gordon Guest

    ern wrote:

    <snip>

    > if(result == EXIT_PROGRAM){
    > printf("Exit script command detected.\n");
    > exit(0); //Thought this line would exit, but it doesn't
    > // It requires that you press enter after for console
    > termination.
    > }


    It's probable that the application has ended but the IDE is being
    helpful and keeping the command window open for you. Try running it
    outside the IDE. As far as the C language is concerned the call to exit
    is enough.
    --
    Flash Gordon, living in interesting times.
    Web site - http://home.flash-gordon.me.uk/
    comp.lang.c posting guidelines and intro:
    http://clc-wiki.net/wiki/Intro_to_clc
     
    Flash Gordon, Mar 23, 2006
    #9
  10. ern

    ern Guest

    Default User wrote:
    > ern wrote:
    >
    > >
    > > pemo wrote:

    >
    > > > Post a working sample of the code - then we might be able to help.

    >
    > > if(result == EXIT_PROGRAM){
    > > printf("Exit script command detected.\n");
    > > exit(0); //Thought this line would exit, but it doesn't
    > > // It requires that you press enter after for console
    > > termination.
    > > }

    >
    > As I said elsewhere, it's the IDE. Try running that from a command you
    > opened, you'll see the expected behavior.
    >
    >
    >
    > Brian


    I have tried the following methods, all of which are outside the IDE:

    1. Running it from the command line.
    2. Double clicking in Windows Explorer
    3. Running from a python script

    None of them seem to get rid of the console app after exit(0) is
    encountered. They all require that I press enter inside the console
    window... THEN the window disappears. Arghhh...
     
    ern, Mar 23, 2006
    #10
  11. ern

    ern Guest

    Flash Gordon wrote:
    > ern wrote:
    >
    > <snip>
    >
    > > if(result == EXIT_PROGRAM){
    > > printf("Exit script command detected.\n");
    > > exit(0); //Thought this line would exit, but it doesn't
    > > // It requires that you press enter after for console
    > > termination.
    > > }

    >
    > It's probable that the application has ended but the IDE is being
    > helpful and keeping the command window open for you. Try running it
    > outside the IDE. As far as the C language is concerned the call to exit
    > is enough.
    > --
    > Flash Gordon, living in interesting times.
    > Web site - http://home.flash-gordon.me.uk/
    > comp.lang.c posting guidelines and intro:
    > http://clc-wiki.net/wiki/Intro_to_clc


    I closed the IDE, and put the executable file in a directory where the
    IDE could not see it. The problem remains though...
     
    ern, Mar 24, 2006
    #11
  12. ern wrote:
    > Right now I'm using exit(0) to [attemp to] terminate my program. My
    > program is a console .exe application. After the "exit(0)" line of
    > code is encountered, the console application waits for an enter press,
    > before terminating. I want it to terminate completely without having
    > to press enter manually. Anybody know what I might be missing here ?


    Are you using your IDE's test console? Those often require a keypress
    in general so that you can see program output without the window
    closing.

    Other than that, I have no experience with EXEs.
     
    Andrew Poelstra, Mar 24, 2006
    #12
  13. "ern" <> writes:
    > Flash Gordon wrote:
    >> ern wrote:
    >>
    >> <snip>
    >>
    >> > if(result == EXIT_PROGRAM){
    >> > printf("Exit script command detected.\n");
    >> > exit(0); //Thought this line would exit, but it doesn't
    >> > // It requires that you press enter after for console
    >> > termination.
    >> > }

    >>
    >> It's probable that the application has ended but the IDE is being
    >> helpful and keeping the command window open for you. Try running it
    >> outside the IDE. As far as the C language is concerned the call to exit
    >> is enough.

    >
    > I closed the IDE, and put the executable file in a directory where the
    > IDE could not see it. The problem remains though...


    Once your program calls exit(), the program itself terminates.
    (Unless you do something really ugly with atexit(), but I presume
    you're not doing that.) Something else is keeping the window open,
    and that "something else" is outside the scope of the comp.lang.c
    newsgroup.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Mar 24, 2006
    #13
  14. ern

    Pedro Graca Guest

    ern wrote:
    > Default User wrote:
    >> ern wrote:
    >> > if(result == EXIT_PROGRAM){
    >> > printf("Exit script command detected.\n");
    >> > exit(0); //Thought this line would exit, but it doesn't
    >> > // It requires that you press enter after for console
    >> > termination.
    >> > }

    >>
    >> As I said elsewhere, it's the IDE. Try running that from a command you
    >> opened, you'll see the expected behavior.

    >
    > I have tried the following methods, all of which are outside the IDE:
    >
    > 1. Running it from the command line.
    > 2. Double clicking in Windows Explorer
    > 3. Running from a python script
    >
    > None of them seem to get rid of the console app after exit(0) is
    > encountered. They all require that I press enter inside the console
    > window... THEN the window disappears. Arghhh...


    1.

    You are at a command line window.
    You change to the directory where your program resides

    C:\> cd directory\of\my\exe

    you execute the program

    C:\director\of\my\exe> app

    and, right after pressing <ENTER>, does a /new/ window appear?
    If yes, why? What makes the new window appear?

    --
    If you're posting through Google read <http://cfaj.freeshell.org/google>
     
    Pedro Graca, Mar 24, 2006
    #14
  15. ern

    Neil Guest

    Default User wrote:
    > ern wrote:
    >
    >> Default User wrote:

    >
    >>> Are you running this from an IDE, like Visual Studio or some such
    >>> thing?

    >
    >> Visual C++ IDE

    >
    > There you go. That's not a language thing, it's just the IDE. People
    > don't want that window disappearing, because you can't see the output.
    > You have to ask on a Visual Studion newsgroup of some sort whether that
    > can be changed. There's nothing C can do.
    >
    >
    >
    > Brian
    >

    There is nothing to do.
    build a release version, it will not have the press a key.
     
    Neil, Mar 24, 2006
    #15
  16. ern

    ern Guest

    Pedro Graca wrote:
    > ern wrote:
    > > Default User wrote:
    > >> ern wrote:
    > >> > if(result == EXIT_PROGRAM){
    > >> > printf("Exit script command detected.\n");
    > >> > exit(0); //Thought this line would exit, but it doesn't
    > >> > // It requires that you press enter after for console
    > >> > termination.
    > >> > }
    > >>
    > >> As I said elsewhere, it's the IDE. Try running that from a command you
    > >> opened, you'll see the expected behavior.

    > >
    > > I have tried the following methods, all of which are outside the IDE:
    > >
    > > 1. Running it from the command line.
    > > 2. Double clicking in Windows Explorer
    > > 3. Running from a python script
    > >
    > > None of them seem to get rid of the console app after exit(0) is
    > > encountered. They all require that I press enter inside the console
    > > window... THEN the window disappears. Arghhh...

    >
    > 1.
    >
    > You are at a command line window.
    > You change to the directory where your program resides
    >
    > C:\> cd directory\of\my\exe
    >
    > you execute the program
    >
    > C:\director\of\my\exe> app
    >
    > and, right after pressing <ENTER>, does a /new/ window appear?
    > If yes, why? What makes the new window appear?
    >
    > --
    > If you're posting through Google read <http://cfaj.freeshell.org/google>


    No, a new window does not appear. The text-based app runs inside the
    window that invoked it.
     
    ern, Mar 24, 2006
    #16
  17. ern

    Pedro Graca Guest

    ern wrote:
    >
    > Pedro Graca wrote:
    >> ern wrote:
    >> > Default User wrote:
    >> >> ern wrote:
    >> >> > if(result == EXIT_PROGRAM){
    >> >> > printf("Exit script command detected.\n");
    >> >> > exit(0); //Thought this line would exit, but it doesn't
    >> >> > // It requires that you press enter after for console
    >> >> > termination.
    >> >> > }
    >> >>
    >> >> As I said elsewhere, it's the IDE. Try running that from a command you
    >> >> opened, you'll see the expected behavior.
    >> >
    >> > I have tried the following methods, all of which are outside the IDE:
    >> >
    >> > 1. Running it from the command line.
    >> > 2. Double clicking in Windows Explorer
    >> > 3. Running from a python script
    >> >
    >> > None of them seem to get rid of the console app after exit(0) is
    >> > encountered. They all require that I press enter inside the console
    >> > window... THEN the window disappears. Arghhh...

    >>
    >> 1.
    >>
    >> You are at a command line window.
    >> You change to the directory where your program resides
    >>
    >> C:\> cd directory\of\my\exe
    >>
    >> you execute the program
    >>
    >> C:\director\of\my\exe> app
    >>
    >> and, right after pressing <ENTER>, does a /new/ window appear?
    >> If yes, why? What makes the new window appear?

    >
    > No, a new window does not appear. The text-based app runs inside the
    > window that invoked it.


    And when the program reaches (and executes) the ``exit(0);'' statement
    does it or does it not terminate?

    If it terminates (and the DOS prompt shows up ready for input) there's
    nothing wrong with your program, your compiler, or your operating system.

    --
    If you're posting through Google read <http://cfaj.freeshell.org/google>
     
    Pedro Graca, Mar 24, 2006
    #17
  18. ern

    Jim Cook Guest


    >>>>>if(result == EXIT_PROGRAM){
    >>>>> printf("Exit script command detected.\n");
    >>>>> exit(0); //Thought this line would exit, but it doesn't


    >>>1. Running it from the command line.
    >>>2. Double clicking in Windows Explorer
    >>>3. Running from a python script


    >>>None of them seem to get rid of the console app after exit(0) is
    >>>encountered. They all require that I press enter inside the console
    >>>window... THEN the window disappears. Arghhh...


    >>You are at a command line window.
    >>You change to the directory where your program resides
    >>
    >> C:\> cd directory\of\my\exe
    >>
    >>you execute the program
    >>
    >> C:\director\of\my\exe> app


    > No, a new window does not appear. The text-based app runs inside the
    > window that invoked it.


    To make a wild guess, you're running under Windows. If so, right click
    the title bar (while your app is running) and choose properties. There's
    a checkbox relating to close on exit. If that solves the problem,
    comp.lang.c was WAY the wrong group to post into.

    However, according to what I glean from the thread quoted above, you've
    said that the text app runs inside the window that invoked it, and that
    after it finishes, you press Enter, and the whole window disappears. I
    can't imagine just what would do that.

    It's clear to experienced C gurus that the exit() code does in fact exit
    your program. Without checking to see if I'll get killed for suggesting
    something non-ANSI, make sure there's no onexit() type of call that asks
    for a return.
     
    Jim Cook, Mar 24, 2006
    #18
  19. ern

    Default User Guest

    Neil wrote:

    > Default User wrote:
    > > ern wrote:
    > >
    > > > Default User wrote:

    > >
    > > > > Are you running this from an IDE, like Visual Studio or some
    > > > > such thing?

    > >
    > > > Visual C++ IDE

    > >
    > > There you go. That's not a language thing, it's just the IDE. People
    > > don't want that window disappearing, because you can't see the
    > > output. You have to ask on a Visual Studion newsgroup of some sort
    > > whether that can be changed. There's nothing C can do.


    > There is nothing to do.
    > build a release version, it will not have the press a key.



    I don't see that behavior.

    As I said, the OP needs to go to a newsgroup dedicated to his platform,
    where he can get good, peer-checked advice. This is not the place to
    discuss it.



    Brian
     
    Default User, Mar 24, 2006
    #19
  20. Jim Cook <> writes:
    [...]
    > It's clear to experienced C gurus that the exit() code does in fact
    > exit your program. Without checking to see if I'll get killed for
    > suggesting something non-ANSI, make sure there's no onexit() type of
    > call that asks for a return.


    If you mean atexit(), that's standard C (I mentioned the possibility
    elsewhere in this thread.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Mar 24, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,905
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. Andrew Thompson

    Eclipse terminating, exit code 1

    Andrew Thompson, Dec 12, 2003, in forum: Java
    Replies:
    13
    Views:
    14,450
    Sudsy
    Dec 13, 2003
  3. Jeffrey Barish
    Replies:
    0
    Views:
    302
    Jeffrey Barish
    May 28, 2004
  4. Ian Wilson
    Replies:
    4
    Views:
    646
    Ian Wilson
    Jan 24, 2007
  5. akineko
    Replies:
    3
    Views:
    2,635
    Jesse Noller
    Jan 29, 2009
Loading...

Share This Page