• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Restarting an app -- AppleScript 'launch' in a detached shell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Restarting an app -- AppleScript 'launch' in a detached shell


  • Subject: Re: Restarting an app -- AppleScript 'launch' in a detached shell
  • From: Andrew Farmer <email@hidden>
  • Date: Sun, 3 Aug 2008 21:22:32 -0700

On 03 Aug 08, at 19:53, Michael Ash wrote:
On Sun, Aug 3, 2008 at 5:12 PM, Andrew Farmer <email@hidden> wrote:
On 03 Aug 08, at 14:00, Steve Cronin wrote:

I am trying to simply restart my app. To my dismay, I cannot find a way
to do this in Cocoa.
Please enlighten me if I have failed to understand something!!


After perusing the archives, what makes the most sense to me is to launch
a detached shell that executes a simple AppleScript.
The script has a delay of 2 seconds and then simply does a 'launch'.

You're overcomplicating things.

int main(int argc, char **argv) {
      if(fork() || fork()) exit(0);
      sleep(2);
      execl(argv[1], argv[1], NULL);
      exit(1);
}

Launch this with a single argument - the path to your application's
executable. It'll background itself, sleep two seconds, and exec your
application.

This is, IMO, a rather bad approach. If your app takes longer than two seconds to quit, it will fail. It's generally a bad idea to use exec() on GUI apps. And you end up creating three subprocesses for no particularly good reason.

The double-fork is to fully detach the child process from the parent - note that all of the parent processes immediately die, because fork() returns nonzero.


The point about exec() is entirely correct, though - LaunchServices is probably the right way to go.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Restarting an app -- AppleScript 'launch' in a detached shell
      • From: "Michael Ash" <email@hidden>
    • Re: Restarting an app -- AppleScript 'launch' in a detached shell
      • From: "Kyle Sluder" <email@hidden>
References: 
 >Restarting an app -- AppleScript 'launch' in a detached shell (From: Steve Cronin <email@hidden>)
 >Re: Restarting an app -- AppleScript 'launch' in a detached shell (From: Andrew Farmer <email@hidden>)
 >Re: Restarting an app -- AppleScript 'launch' in a detached shell (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: How to get music list?
  • Next by Date: Re: How to get the value of a NSNumber contained in an array while debugging ?
  • Previous by thread: Re: Restarting an app -- AppleScript 'launch' in a detached shell
  • Next by thread: Re: Restarting an app -- AppleScript 'launch' in a detached shell
  • Index(es):
    • Date
    • Thread