exit-code

Run MsiExec from PowerShell and get Return Code

自古美人都是妖i 提交于 2019-12-02 18:56:24
With BAT/CMD script I can simply use "msiexec /i <whatever.msi> /quiet /norestart" and then check %errorlevel% for the result. With VBScript , using the Wscript.Shell object Run() method, I can get the result like this: "result = oShell.Run("msiexec /i ...", 1, True)" How can I do this with PowerShell? I would wrap that up in Start-Process and use the ExitCode property of the resulting process object. For example (Start-Process -FilePath "msiexec.exe" -ArgumentList "<<whatever>>" -Wait -Passthru).ExitCode $LastExitCode or $? depending on what you're after. The former is an integer, the latter

How to trap exit code in Bash script

不想你离开。 提交于 2019-12-02 17:53:13
There're many exit points in my bash code. I need to do some clean up work on exit, so I used trap to add a callback for exit like this: trap "mycleanup" EXIT The problem is there're different exit codes, I need to do corresponding cleanup works. Can I get exit code in mycleanup? I think you can use $? to get the exit code. The accepted answer is basically correct, I just want to clarify things. The following example works well: #!/bin/bash cleanup() { rv=$? rm -rf "$tmpdir" exit $rv } tmpdir="$(mktemp)" trap "cleanup" INT TERM EXIT # Do things... But you have to be more careful if doing

What is an appropriate way to programmatically exit an application?

好久不见. 提交于 2019-12-02 12:44:22
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.in)); //Other logic goes here... if (br.readLine().equalsIgnoreCase("Q")){ System.exit(0); } } catch

Will calling System.exit(0); from an object outside of main run garbage collection?

半世苍凉 提交于 2019-12-02 04:32:29
I plan to use an object which is called by my main method to exit the entire program. The object has a method which just runs a System.exit(0). My question is, is this a safe thing to do? If I run System.exit(0) from another object, will garbage collection still clean out the entire program from memory, or will I have issues cleaning the calling class from memory? My thoughts are that either since the JVM will be terminated, the calling class will be garbage-collected, or that I might have issues cleaning the calling class from memory since the object's stack frame is above the main stack

Closing function in a VB.NET console application

筅森魡賤 提交于 2019-12-02 04:26:52
问题 How can I fire off a function when it detects the console closing when using Environment.Exit(0) ? 回答1: The simplest way of doing this is probably to handle the AppDomain.ProcessExit event, which is raised when the application's parent process exits. For example: Module MyApp Sub Main() ' Attach the event handler method AddHandler AppDomain.CurrentDomain.ProcessExit, AddressOf MyApp_ProcessExit ' Do something ' ... Environment.Exit(0) End Sub Private Sub MyApp_ProcessExit(sender As Object, e

How to terminate a program with Ctrl-D?

风格不统一 提交于 2019-12-02 01:44:06
问题 I am trying to write a simple program that simulates a calculator. I would like the program to exit or turn-off when the Ctrl + D keystroke is made. I searched through stackoverflow and saw other examples of Ctrl + C or Ctrl + A but the examples are in java and C. for C: (scanf("%lf", &var); for java, a SIGINT is raised when Ctrl + Z is pressed. signal(SIGINT,leave); for(;;) getchar(); I am wondering what can I do for Ctrl + D in C++... Thanks everyone! 回答1: If you need to terminate with Ctrl

How to terminate a program with Ctrl-D?

試著忘記壹切 提交于 2019-12-01 20:24:57
I am trying to write a simple program that simulates a calculator. I would like the program to exit or turn-off when the Ctrl + D keystroke is made. I searched through stackoverflow and saw other examples of Ctrl + C or Ctrl + A but the examples are in java and C. for C: (scanf("%lf", &var); for java, a SIGINT is raised when Ctrl + Z is pressed. signal(SIGINT,leave); for(;;) getchar(); I am wondering what can I do for Ctrl + D in C++... Thanks everyone! If you need to terminate with Ctrl-D while reading input. while ( std::cin ) // Ctrl-D will terminate the loop { ... } Will Robinson Ctrl + D

Xcode Error: Command /usr/bin/codesign failed with exit code 1

北城余情 提交于 2019-12-01 16:29:57
I have no idea why I am getting this error. I believe that I have all the correct provisioning profiles and such. I did just move to a new computer but I did also bring over the private keychain developer key. I have my developer files synced with Dropbox so I didn't need to move over the Xcode project. Here is the error: CodeSign "/Users/michaellindahl/Library/Developer/Xcode/DerivedData/Fraction_Calculator-cgirhuuvywfnsyenisucsuauquoz/Build/Products/Debug-iphoneos/Fraction Calculator Pro.app" cd "/Users/michaellindahl/Dropbox/Xcode/lindahl studios/FractionCalculator" setenv CODESIGN_ALLOCATE

Xcode Error: Command /usr/bin/codesign failed with exit code 1

蹲街弑〆低调 提交于 2019-12-01 15:47:14
问题 I have no idea why I am getting this error. I believe that I have all the correct provisioning profiles and such. I did just move to a new computer but I did also bring over the private keychain developer key. I have my developer files synced with Dropbox so I didn't need to move over the Xcode project. Here is the error: CodeSign "/Users/michaellindahl/Library/Developer/Xcode/DerivedData/Fraction_Calculator-cgirhuuvywfnsyenisucsuauquoz/Build/Products/Debug-iphoneos/Fraction Calculator Pro

How to test the exit status from IPC::Run3

微笑、不失礼 提交于 2019-12-01 13:02:36
I'm trying to test the Perl module IPC::Run3 but having difficulty in checking whether a command is failed or successful. I know that IPC::Run3 issues an exit code if something is wrong with its arguments, but what about if the arguments are ok but the command does not exist? How can I test the following example? Having a subroutine to call Run3 sub runRun3 { my $cmd = shift; my ($stdout, $stderr); run3($cmd, \undef, \$stdout, \$stderr); # if( $? == -1 ) { if (! $stdout and ! $stderr) { die "Something is wrong"; } else { print "OK \n"; } } when command $cmds[0] below is executed (the ls