Questions tagged [exit]

Exiting, quitting, or halting refers to the termination of a process or program.

2366 questions
780
votes
7 answers

In a Bash script, how can I exit the entire script if a certain condition occurs?

I'm writing a script in Bash to test some code. However, it seems silly to run the tests if compiling the code fails in the first place, in which case I'll just abort the tests. Is there a way I can do this without wrapping the entire script inside…
samoz
  • 51,592
  • 52
  • 138
  • 190
717
votes
15 answers

What are the differences in die() and exit() in PHP?

What are the differences between die() and exit() functions in PHP? I think both have the same functionality, but I doubt there is something different in both... what is it?
coderex
  • 24,487
  • 43
  • 111
  • 167
669
votes
8 answers

Automatic exit from Bash shell script on error

I've been writing some shell script and I would find it useful if there was the ability to halt the execution of said shell script if any of the commands failed. See below for an example: #!/bin/bash cd some_dir ./configure…
radman
  • 14,904
  • 9
  • 38
  • 56
477
votes
11 answers

Difference between return and exit in Bash functions

What is the difference between the return and exit statement in Bash functions with respect to exit codes?
lecodesportif
  • 9,527
  • 8
  • 31
  • 53
450
votes
2 answers

Difference between exit() and sys.exit() in Python

In Python, there are two similarly-named functions, exit() and sys.exit(). What's the difference and when should I use one over the other?
Drake Guan
  • 12,774
  • 11
  • 52
  • 92
352
votes
21 answers

SQL Server - stop or break execution of a SQL script

Is there a way to immediately stop execution of a SQL script in SQL server, like a "break" or "exit" command? I have a script that does some validation and lookups before it starts doing inserts, and I want it to stop if any of the validations or…
Andy White
  • 81,400
  • 46
  • 171
  • 205
287
votes
10 answers

How to exit from Python without traceback?

I would like to know how to I exit from Python without having an traceback dump on the output. I still want want to be able to return an error code but I do not want to display the traceback log. I want to be able to exit using exit(number) without…
sorin
  • 137,198
  • 150
  • 472
  • 707
285
votes
4 answers

What is the command to exit a Console application in C#?

What is the command in C# for exit a Console Application?
Sababoni
  • 4,228
  • 4
  • 16
  • 18
267
votes
15 answers

Checking Bash exit status of several commands efficiently

Is there something similar to pipefail for multiple commands, like a 'try' statement but within bash. I would like to do something like this: echo "trying stuff" try { command1 command2 command3 } And at any point, if any command fails,…
jwbensley
  • 8,994
  • 18
  • 65
  • 89
256
votes
9 answers

How to exit if a command failed?

I am a noob in shell-scripting. I want to print a message and exit my script if a command fails. I've tried: my_command && (echo 'my_command failed; exit) but it does not work. It keeps executing the instructions following this line in the script.…
user459246
  • 2,709
  • 2
  • 13
  • 7
222
votes
3 answers

How to undo the effect of "set -e" which makes bash exit immediately if any command fails?

After entering set -e in an interactive bash shell, bash will exit immediately if any command exits with non-zero. How can I undo this effect?
Tianyi Cui
  • 3,723
  • 3
  • 16
  • 18
216
votes
9 answers

How to properly exit a C# application?

I have a published application in C#. The problem here is whenever I close the main form by clicking on the red exit button, it closes the form but it doesn't close the application. I found this out when I tried shutting down the computer, hopeful…
John Ernest Guadalupe
  • 5,571
  • 9
  • 34
  • 65
215
votes
10 answers

How do I step out of a loop with Ruby Pry?

I'm using Pry with my Rails application. I set binding.pry inside a loop in my model to try and debug a problem. For example: (1..100).each do |i| binding.pry puts i end When I type quit, it goes to the next iteration and stops again. Is there…
Ryan
  • 8,882
  • 5
  • 36
  • 41
207
votes
8 answers

return statement vs exit() in main()

Should I use exit() or just return statements in main()? Personally I favor the return statements because I feel it's like reading any other function and the flow control when I'm reading the code is smooth (in my opinion). And even if I want to…
Srikanth
  • 11,148
  • 20
  • 64
  • 87
204
votes
35 answers

How to stop C++ console application from exiting immediately?

Lately, I've been trying to learn C++ from this website. Unfortunately whenever I try to run one of the code samples, I see that program open for about a half second and then immediately close. Is there a way to stop the program from closing…
Adam P
  • 4,345
  • 6
  • 27
  • 40
1
2 3
99 100