2

I use a .app to bundle my command line tool (I use a framework).

To quit the app, I use NSapp.terminate(self) and catch it:

func applicationWillTerminate(_ aNotification: Notification) {

    if exitSuccessful {
        print("successful")
    } else {
        print("not successful")
        exit(1)
    } 
}

Doing so exits the application, but quite harshly, as no deconstruction/release or anything is done after exit(1). On my machine, exit code is set correctly, but I had reports it exits with code 132 (SIGILL).

I've found something related, but only for "pure" command line utilities: http://ericasadun.com/2014/06/13/swift-command-line-exit-codes/

Any idea?

Francois T.
  • 430
  • 1
  • 5
  • 9
  • I'm not sure what you're asking. The applicationWillTerminate delegate is called when the application is about to quit. Then it quits. You don't have to exit manually. But if you want to "clean" things before it exits if your exitSuccessful bool is false, then just do that instead of calling "exit". :) Unless I misunderstood your question? – Eric Aya Mar 15 '17 at 14:21
  • Thank you for answering! A process when exiting will return an exit code. 0 when things are success full, non zero for other cases. My goal is to exit 1 if there's an error so it can be caught by a script calling the app – Francois T. Mar 15 '17 at 14:33
  • Related to this issue → https://github.com/ftiff/MacAdminQuitApp/issues/3 – Francois T. Mar 15 '17 at 14:34
  • Possible duplicate of http://stackoverflow.com/questions/2742133/any-good-way-to-set-the-exit-status-of-a-cocoa-application – Eric Aya Mar 15 '17 at 14:36

0 Answers0