473,320 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Terminating program with "exit( )"

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
19 11417
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
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
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
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
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
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
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
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
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
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

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
"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
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
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
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
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
>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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: tdi | last post by:
Ok, stupid question for the day. I'm reading the interview with Steve Moret and he says: "Once a lot of scripts started going in we knew there was no way we could back out of using Python." I'm...
7
by: Brett | last post by:
What is the C# equivalent of VB.NET's Exit Sub? Thanks, Brett
24
by: Agnes | last post by:
I need to disable the exit button in the form . However, the min. and max. button need to keep it How ? Thanks a lot From Agnes
1
by: Steve Long | last post by:
Hello, does anybody know if the built in support for the "Exit For" statement is just a left over from earier versions of VB and therefore inefficient or if it's truely a VB.NET language feature?...
41
by: SkyBlue | last post by:
Hi, can someone explain why the following simple C code segfaulted? I've stared it for 30mins but couldn't find the problem. Thx in advance #include <stdio.h> int main() { char *one; char...
10
by: Zytan | last post by:
Threads are not auto-terminated when the main form closes (not that they should be). What's the best way to terminate them when the program exits? Catch the on close message of the form, and give...
2
by: InvalidPointers | last post by:
Doing some work on the ol' memory manager this evening and recently I've been having read access violations occur after the actual program exit. The problematic line appears as follows, it appears to...
1
by: JEJE | last post by:
To All, What is the difference between the following Exit code?? Exit (0)?? Exit(1)?? Exit (2)??
2
by: dstork | last post by:
Anyone know how to rename the "Exit Access" command at the bottom of the Office menu. I'd like to rename it to "Exit" as I had done in previous versions of Access. I know I can disable it with ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.