Terminating program with "exit( )"

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 ?

Advertisements

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.

Advertisements

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 ?

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.

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 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.

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.

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.

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

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.

"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.

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?

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.

>>>>>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.

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.

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.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!