Terminating program with "exit( )"

E

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 ?
 
D

Default User

ern said:
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
 
P

pemo

ern said:
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.
 
E

ern

Default said:
ern said:
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

Visual C++ IDE
 
E

ern

pemo said:
ern said:
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.

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

Default User

ern said:
Default User wrote:
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
 
D

Default User

ern said:
pemo 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.



Brian
 
I

Ian Collins

ern said:
pemo said:
ern said:
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.


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

Flash Gordon

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

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

ern

Default said:
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...
 
E

ern

Flash said:
ern wrote:



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

Andrew Poelstra

ern said:
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.
 
K

Keith Thompson

ern said:
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.
 
P

Pedro Graca

ern said:
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?
 
N

Neil

Default said:
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.
 
E

ern

Pedro said:
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.
 
P

Pedro Graca

ern said:
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.
 
J

Jim Cook

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

Default User

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
 
K

Keith Thompson

Jim Cook said:
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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top