Exiting, quitting, or halting refers to the termination of a process or program.
Questions tagged [exit]
2585 questions
123
votes
8 answers
Removing created temp files in unexpected bash exit
I am creating temporary files from a bash script. I am deleting them at the end of the processing, but since the script is running for quite a long time, if I kill it or simply CTRL-C during the run, the temp files are not deleted.
Is there a way I…

skinp
- 4,157
- 4
- 27
- 20
122
votes
7 answers
ruby system command check exit code
I have a bunch of system calls in ruby such as the following and I want to check their exit codes simultaneously so that my script exits out if that command fails.
system("VBoxManage createvm --name test1")
system("ruby test.rb")
I want something…

user1530318
- 25,507
- 15
- 37
- 48
119
votes
5 answers
What is the difference between exit and return?
What is difference between return and exit statement in C programming when called from anywhere in a C program?

shona
- 1,277
- 3
- 11
- 5
112
votes
3 answers
Equivalent VB keyword for 'break'
I just moved over to the Visual Basic team here at work.
What is the equivalent keyword to break in Visual Basic, that is, to exit a loop early but not the method?

Tyronomo
- 2,047
- 2
- 15
- 22
109
votes
9 answers
break/exit script
I have a program that does some data analysis and is a few hundred lines long.
Very early on in the program, I want to do some quality control and if there is not enough data, I want the program to terminate and return to the R console. Otherwise,…

user2588829
- 1,523
- 3
- 10
- 20
107
votes
7 answers
How to effectively abort the execution of a Bash script from a function
I was using the "exit 1" statement in my Bash functions to terminate the whole script and it worked fine:
function func()
{
echo "Goodbye"
exit 1
}
echo "Function call will abort"
func
echo "This will never be printed"
But then I realized…

LiMar
- 2,822
- 3
- 22
- 28
106
votes
4 answers
Stop execution of Ruby script
Is there a method like exit or die in PHP which stops the execution of a Ruby script?

adaxa
- 1,580
- 2
- 14
- 17
105
votes
4 answers
exit with error message in bash (oneline)
Is it possible to exit on error, with a message, without using if statements?
[[ $TRESHOLD =~ ^[0-9]+$ ]] || exit ERRCODE "Threshold must be an integer value!"
Of course the right side of || won't work, just to give you better idea of what I am…

branquito
- 3,864
- 5
- 35
- 60
103
votes
4 answers
WPF Command Line
I am trying to create a WPF application that takes command line arguments. If no arguments are given, the main window should pop up. In cases of some specific command line arguments, code should be run with no GUI and exit when finished. Any…

bingles
- 11,582
- 10
- 82
- 93
100
votes
4 answers
How to exit a go program honoring deferred calls?
I need to use defer to free allocations manually created using C library, but I also need to os.Exit with non 0 status at some point. The tricky part is that os.Exit skips any deferred instruction:
package main
import "fmt"
import "os"
func main()…

marcio
- 10,002
- 11
- 54
- 83
99
votes
10 answers
Capture console exit C#
I have a console application that contains quite a lot of threads. There are threads that monitor certain conditions and terminate the program if they are true. This termination can happen at any time.
I need an event that can be triggered when…

ZeroKelvin
- 1,923
- 2
- 15
- 9
96
votes
10 answers
How do I exit a while loop in Java?
What is the best way to exit/terminate a while loop in Java?
For example, my code is currently as follows:
while(true){
if(obj == null){
// I need to exit here
}
}

BalaB
- 3,687
- 9
- 36
- 58
92
votes
3 answers
How to handle a SIGTERM
Is there a way in Java to handle a received SIGTERM?

Martijn Courteaux
- 67,591
- 47
- 198
- 287
92
votes
6 answers
Exit with error code in go?
What's the idiomatic way to exit a program with some error code?
The documentation for Exit says "The program terminates immediately; deferred functions are not run.", and log.Fatal just calls Exit. For things that aren't heinous errors, terminating…

dan
- 4,262
- 7
- 25
- 40
86
votes
7 answers
Stopping a JavaScript function when a certain condition is met
I can't find a recommended way to stop a function part way when a given condition is met. Should I use something like exit or break?
I am currently using this:
if ( x >= 10 ) { return; }
// other conditions;

Rhys
- 975
- 1
- 6
- 12