exit

ruby at_exit exit status

自古美人都是妖i 提交于 2019-12-04 17:16:23
问题 Can i determine selves process exit status in at_exit block? at_exit do if this_process_status.success? print 'Success' else print 'Failure' end end 回答1: Although the documentation on this is really thin, $! is set to be the last exception that occurs, and after an exit() call this is a SystemExit exception. Putting those two together you get this: at_exit do if ($!.success?) print 'Success' else print 'Failure' end end 回答2: using idea from tadman at_exit do if $!.nil? || $!.is_a?(SystemExit)

Return an exit code without closing shell

风格不统一 提交于 2019-12-04 16:06:55
问题 I'd like to return an exit code from a BASH script that is called within another script, but could also be called directly. It roughly looks like this: #!/bin/bash dq2-get $1 if [ $? -ne 0 ]; then echo "ERROR: ..." # EXIT HERE fi # extract, do some stuff # ... Now in the line EXIT HERE the script should exit and return exit code 1. The problem is that I cannot use return , because when I forget to source the script instead of calling it, return will not exit, and the rest of the script will

exit(0) vs return 0

拥有回忆 提交于 2019-12-04 10:37:03
问题 When exit(0) is used to exit from program, destructors for locally scoped non-static objects are not called. But destructors are called if return 0 is used.Note that static objects will be cleaned up even if we call exit(). There should be some reason behind this logic. i just want to know what it is? Thank you. 回答1: In the case of exit( 0 ) , you're calling a function. You don't expect the destructors of local variables to be called if you're calling a function. And the compiler doesn't know

Does Application.ApplicationExit event work to be notified of exit in non-Winforms apps?

烂漫一生 提交于 2019-12-04 09:41:13
问题 Our code library needs to be notified when the application is exiting. So we have subscribed to the System.Window.Forms.Application.ApplicationExit event. This works nicely for Winforms apps, but does it also work for other types of applications such as console apps, services, and web apps (such as ASP.NET)? The namespace would suggest that it doesn't, and it presumably gets raised when Application.Exit() is called (explicitly or implictly), which may not be correct to call for these other

Exit/Finish an app/activity - android

寵の児 提交于 2019-12-04 09:06:16
问题 I've got 4 activities say Act1 , Act2 , Act3 and Act4 . A button in Act1 opens Act2, a button in Act2 opens Act3, a button in Act3 opens Act4. I want two things to be done: I've a button in Act4 which directs the user to Act1, the prob is when the user clicks back in Act1, i want to close the app instead of opening the Act4.. I've option in menu 'exit' in all activities when the user choose it, i want to close the app instead of going back to previous activity. Tried using finish(); but it

VS2008 unit tests - assert method exits

有些话、适合烂在心里 提交于 2019-12-04 08:40:53
I'm trying to write a C# unit test with VS 2008's built-in unit testing framework and the method I'm testing calls Environment.Exit(0) . When I call this method in my unit test, my unit test is Aborted. The method should indeed be calling Exit , and I want a way to test that it does, and also to test the exit code that it uses. How might I do this? I looked at Microsoft.VisualStudio.TestTools.UnitTesting Namespace but didn't see anything that looked relevant. [TestMethod] [DeploymentItem("myprog.exe")] public void MyProgTest() { // Want to ensure this Exit's with code 0: MyProg_Accessor

D exit statement

核能气质少年 提交于 2019-12-04 08:20:39
Does D have an exit statement, similar to the one in java, python, c/c++. Which will (big shocker) exit execution of the program? Something like exit(); If you want exit , then use C's exit function. import core.stdc.stdlib; void main() { exit(-1); } I'm not quite sure how that affects the D runtime and whatnot though. It might be that stuff doesn't get cleaned up like you'd normally want, or it might be just fine. I wouldn't really advise using it in general though, since there are usually better ways to handle exiting a program. But the declaration for the C function is in druntime, so it's

When abort() is preferred over exit()?

。_饼干妹妹 提交于 2019-12-04 08:03:46
问题 I know the differences between the two . One notable thing is that abort() sends SIGABRT signal, so it may be relevant when your software relies on them. But for a typical application exit() seems to be more safe version of abort()...? Are there any other concerns to use abort() instead of exit()? 回答1: Using abort will dump core, if the user has core dumps enabled. So as a rule of thumb, I'd use abort if you're so unsure about what's gone wrong that the only way to get useful information

Better replacement for exit(), atexit() in C

拜拜、爱过 提交于 2019-12-04 04:03:41
I am new to C programming. I used to think using exit() was the cleanest way of process termination (as it is capable of removing temporary files, closing open files, normal process termination...), but when I tried man exit command on the terminal (Ubuntu 16.04.5, gcc 5.4.0) I saw the following line: The exit() function uses a global variable that is not protected, so it is not thread-safe. After that I tried to make some research about better replacement for exit() (to change my programming behavior from the beginning). While doing that I faced with this question in which side effects of

Close app when hitting back button on android

跟風遠走 提交于 2019-12-04 03:42:10
So my login Activity is the first screen you see. When you hit the back button, it exits the app, good. So I open up the app again. After logging in, I am now in my main Activity. How do I make it so when I hit the back button now, it exits the app rather than going back to the login Activity? When you push the new activity, call finish() on the previous, otherwise it will remain on the stack, therefore appearing when you hit back and pop the current activity. Hope that helps. try this one @Override public void onBackPressed() { super.onBackPressed(); finish(); } 来源: https://stackoverflow.com