exit-code

How can I display a 'naked' error message in PowerShell without an accompanying stacktrace?

时光毁灭记忆、已成空白 提交于 2019-12-04 17:04:12
问题 How can I write to standard error from PowerShell, or trap errors such that: An error message is displayed as an error (truly writing to standard error so that TeamCity and Octopus see it as an error) No stack trace garbage muddles my beautiful, concise error message All these years I've survived by throw ing errors or writing via Write-Error , but I'm tired and old, and in my scripts I just want to see one concise error message. I've been trying every combination of trap , throw , Write

Difference between Environment.Exit and simple return 2 from Main

回眸只為那壹抹淺笑 提交于 2019-12-04 16:57:29
问题 From outside of the application, is there any difference between ... Environment.Exit(2) and static int Main() { ... return 2; } ? 回答1: The most obvious difference is that you can call Environment.Exit from anywhere in your code. Aside from that: Main finishing won't terminate the process if there are other foreground threads executing; Environment.Exit will take down the process anyway. Environment.Exit terminates the process without unwinding the stack and executing finally blocks (at least

Exit code of command substitution in bash local variable assignment [duplicate]

前提是你 提交于 2019-12-04 15:19:03
问题 This question already has answers here : Why does “local” sweep the return code of a command? (2 answers) Closed 3 years ago . How can I check the exit code of a command substitution in bash if the assignment is to a local variable in a function? Please see the following examples. The second one is where I want to check the exit code. Does someone have a good work-around or correct solution for this? $ function testing { test="$(return 1)"; echo $?; }; testing 1 $ function testing { local

How to bypass the 0-255 range limit for sys.exit() in python?

依然范特西╮ 提交于 2019-12-04 12:24:57
问题 In python (on a Linux system), I'm launching a command using os.system() and retrieving the return code. If that return code is different from 0, I would like to make the program exit with that same return code. So I wrote: ret = os.system(cmd) if ret != 0: print "exit with status %s" % ret sys.exit(ret) When the return code is lower than 256, it works fine, but when it's greater than 255, the exit code used is 0. How can I make sys.exit() accept codes greater than 255? Edit: the limit is

eclipse installed but cannot start java returned exit-code = 1

旧街凉风 提交于 2019-12-04 10:24:10
I recently installed eclipse-dsl-juno-SR1-win32-x86_64 and after extracting the files, as I started running Eclipse it gave me the following error : Java was started but returned exit code=1 (required java version=1.5) I checked the reason for this and also tried reinstalling as well as solutions suggested by other discussion forums, but to no avail. I have installed Eclipse IDE for Java and DSL Developers : eclipse-dsl-juno-SR1-win32-x86_64 under the Eclipse Juno SR1 packages AND JDK 1.7.0_11 (x64) I have linked my Environment Variables up correctly and tried to compile a Java file through

How to make a bash function return 1 on any error

天涯浪子 提交于 2019-12-04 10:23:26
I have a fake bash function such as this: has_error() { true echo "Ok..." false echo "Shouldn't be here!" } What I'd like to have happen when I run this function and check the error status: > has_error; echo $? Ok... 1 But what actually happens: > has_error; echo $? Ok... Shouldn't be here! 0 The problem is that the function keeps executing after an error has been thrown, and moreover, I can't even detect that an error was thrown. How can I change this? I could put a set -e at the beginning of the function, but then my whole shell will terminate if an error gets thrown. What I'd like is to

Predictable exit code of crashed process in Windows

家住魔仙堡 提交于 2019-12-04 08:41:37
For a process exiting normally in Windows, the exit code of the process is generally either the return value from main , or the exit code passed to std::exit . %ERRORLEVEL% can then be used to query the exit code, and that can be used to determine whether the program executed either correctly, or there were some exceptional inputs/failures that indicate a particular problem (application specific). However, I'm interested in the exit code if the process crashes. Take a very simple example program: int main() { int * a = nullptr; *a = 0xBAD; return 0; } When I compile this and run in Windows, on

Test Environment.Exit() in C#

南笙酒味 提交于 2019-12-04 07:35:25
Is there in C# some kind of equivalent of ExpectedSystemExit in Java? I have an exit in my code and would really like to be able to test it. The only thing I found in C# is a not really nice workaround . Example Code public void CheckRights() { if(!service.UserHasRights()) { Environment.Exit(1); } } Test Code [TestMethod] public void TestCheckRightsWithoutRights() { MyService service = ... service.UserHasRights().Returns(false); ??? } I am using the VS framework for testing (+ NSubstitute for mocking) but it is not a problem to switch to nunit or whatever for this test. You should use

What is an appropriate way to programmatically exit an application?

≯℡__Kan透↙ 提交于 2019-12-04 05:49:19
问题 I am evaluating user inputs as commands for my application. If the user presses Q , or q , and then hits enter, the application quits and execution terminates. Is there a proper context, or best practices on how to do that? I do not have any resources to release, or anything like that. Should I just use System.exit(0); ? Is there a recommended way to do that? As my first approach I do something like this: while (true){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(System

How to return an exit code from the main block in Nim?

只愿长相守 提交于 2019-12-04 03:33:26
问题 In Nim, to write code that executes as a sort of main function, you do (similar to the is main checks in Python): when isMainModule: echo ("Hello, Nim!") However, for the life of me, I can't figure out how to return an error code. Traditionally there has always been an option to make main functions return int , but since this is not actually in a proc , it doesn't seem like you can return ; the only thing I've figured out how to do is to raise an exception. Surely there is a way to just