Questions tagged [exit]

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

2585 questions
36
votes
9 answers

PHP exit() from within included script, exit parent script?

In PHP, if I use the include() or require() functions to start running code in another script, is there a way to terminate the parent script from within the child? So say I have this in parent.php: require('child.php'); And this in…
batfastad
  • 1,943
  • 3
  • 27
  • 37
36
votes
4 answers

Gracefully Exit Explorer (Programmatically)

How do you gracefully close Explorer programmatically? By that I mean, how do you invoke this function programmatically: Edit: Typo in the picture, it should say "Ctrl-Shift-Right-Click" instead of "Shift-Click".
user541686
  • 205,094
  • 128
  • 528
  • 886
36
votes
4 answers

How to exit a shell script if targeted file doesn't exist?

Given the script below, I would like to avoid the execution of the pipeline if a file does not exist. How may I exit the script straight away if the text file is not found? ls */*.txt | grep ab1 | awk '{print $1, $1}' | sed "s/\"/\"\"/g" | xargs -L1…
amine
  • 449
  • 1
  • 5
  • 12
35
votes
11 answers

Process.HasExited returns true even though process is running?

I have been observing that Process.HasExited sometimes returns true even though the process is still running. My code below starts a process with name "testprogram.exe" and then waits for it to exit. The problem is that sometimes I get thrown the…
johnrl
  • 873
  • 3
  • 14
  • 18
35
votes
1 answer

How can I tell my Cocoa application to quit from within the application itself?

I'm looking for a good way to tell my Cocoa application to quit itself. Rest assured that this will not be used for production code. I'm just looking for an easy way to run one test and then close the application during debugging. I have found that…
e.James
  • 116,942
  • 41
  • 177
  • 214
34
votes
4 answers

How to cleanly exit a threaded C++ program?

I am creating multiple threads in my program. On pressing Ctrl-C, a signal handler is called. Inside a signal handler, I have put exit(0) at last. The thing is that sometimes the program terminates safely but the other times, I get runtime error…
rjlion795
  • 515
  • 1
  • 5
  • 16
34
votes
6 answers

How to use sys.exit() in Python

player_input = '' # This has to be initialized for the loop while player_input != 0: player_input = str(input('Roll or quit (r or q)')) if player_input == q: # This will break the loop if the player decides to quit print("Now…
user2027690
  • 419
  • 3
  • 6
  • 6
34
votes
2 answers

How to end / Force a close to a program (in Clojure)

I am a pretty decent programmer in Java, however I am new to programming in Clojure. In Java, to force an exit of a program, the code used is System.exit(0). Is there any equivalent to this code is Clojure?
Hank
33
votes
3 answers

Generic way to exit a .NET application

I understand that there are a few ways to exit an application, such as Application.Exit(), Application.ExitThread(), Environment.Exit(), etc. I have an external "commons" library, and I'm trying to create a generic FailIf method that logs the…
michael
  • 14,844
  • 28
  • 89
  • 177
33
votes
2 answers

Bash trap on exit from function

Is there possible in bash to call some command when function exits. I mean something like: function foo { # something like this maybe? trap "echo \"exit function foo\"" EXIT # do something } foo And i want exit function foo to be…
bercik
  • 816
  • 1
  • 9
  • 18
33
votes
13 answers

How do I make a C++ console program exit?

Is there a line of code that will terminate the program? Something like python's sys.exit()?
rectangletangle
  • 50,393
  • 94
  • 205
  • 275
33
votes
2 answers

Application.Exit() vs Application.ExitThread() vs Environment.Exit()

I am trying to figure out which I should be using. On closing my WinForm app fires of a Form in Dialog mode. That form runs a Background worker that Syncs the DB with the remote DB and displays it's progress on the "Splash Form." I have a method…
Refracted Paladin
  • 12,096
  • 33
  • 123
  • 233
32
votes
5 answers

How to run one last function before getting killed in Python?

Is there any way to run one last command before a running Python script is stopped by being killed by some other script, keyboard interrupt etc.
dan
  • 585
  • 2
  • 6
  • 8
32
votes
4 answers

Graceful shutdown of a node.JS HTTP server

Here is a simple webserver I am working on var server = require("http").createServer(function(req,resp) { resp.writeHead(200,{"Content-Type":"text/plain"}) resp.write("hi") resp.end() server.close() }) server.listen(80,…
700 Software
  • 85,281
  • 83
  • 234
  • 341
31
votes
12 answers

PHP - exit from IF block

How can I exit a if block if a certain condition is met? I tried using break but it doesn't work: if($bla): $bla = get_bla(); if(empty($bla)) break; do($bla); endif; it says: Fatal error: Cannot break/continue 1 level in...
Alex
  • 66,732
  • 177
  • 439
  • 641