By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,166 Members | 1,695 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,166 IT Pros & Developers. It's quick & easy.

Terminating program with "exit( )"

P: n/a
ern
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 ?

Mar 23 '06 #1
Share this Question
Share on Google+
19 Replies


P: n/a
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.
Mar 23 '06 #2

P: n/a
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*
==============
Mar 23 '06 #3

P: n/a
ern

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

Mar 23 '06 #4

P: n/a
ern

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

Mar 23 '06 #5

P: n/a
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

Mar 23 '06 #6

P: n/a
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
Mar 23 '06 #7

P: n/a
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.
Mar 23 '06 #8

P: n/a
ern

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

Mar 24 '06 #9

P: n/a
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
Mar 24 '06 #10

P: n/a
ern

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

Mar 24 '06 #11

P: n/a

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.

Mar 24 '06 #12

P: n/a
"ern" <er*******@gmail.com> 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) ks***@mib.org <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.
Mar 24 '06 #13

P: n/a
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>
Mar 24 '06 #14

P: n/a
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.
Mar 24 '06 #15

P: n/a
ern

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.

Mar 24 '06 #16

P: n/a
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>
Mar 24 '06 #17

P: n/a
>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.
Mar 24 '06 #18

P: n/a
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
Mar 24 '06 #19

P: n/a
Jim Cook <co****@strobedata.com> 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) ks***@mib.org <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.
Mar 24 '06 #20

This discussion thread is closed

Replies have been disabled for this discussion.