473,836 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
19 11517
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*******@gmai l.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_Keit h) 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(resul t == 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
encountere d. 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****@strobed ata.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_Keit h) 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
2341
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 just getting into Python and am wondering if I'm missing something or this is just a semantic issue. Thanks. -Ted
7
98497
by: Brett | last post by:
What is the C# equivalent of VB.NET's Exit Sub? Thanks, Brett
24
4884
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
1428
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? The reason I ask is because even though the "On Error Goto" statement is still available in .NET, if you use it, it wraps a Try/Catch block around each line of code in that routine from what I understand. If "Exit For" does anything as...
41
2100
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 *two;
10
28771
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 a signal to the threads that they must shut down? Seems I need a destructor for that. Forms don't have an overridable Dispose method. So, how can I react when the form closes? Note my example thread just (abnormally) runs forever until it is...
2
2602
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 have to do with the value passed from my main function: mainret = _tmain(__argc, _targv, _tenviron); I'm no CRT expert, would anyone be able to give me some guidance as to what's going wrong here? I'm also having some difficulty figuring out a...
1
2225
by: JEJE | last post by:
To All, What is the difference between the following Exit code?? Exit (0)?? Exit(1)?? Exit (2)??
2
4008
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 <commands> <command idMso="FileExit" enabled="false"/> </commands> .... but what about renaming it?
0
9668
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10546
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.