I am trying to relaunch my application with some command line arguments. The below code works (without command line arguments)
- (void)relaunchAfterDelay:(float)seconds
{
NSLog(@"relaunchAfterDelay ") ;
NSTask *task = [[NSTask alloc] init] ;
NSArray * args = [ NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"sleep %f; open \"%@\"", seconds, [[NSBundle mainBundle] bundlePath]], nil ] ;
[task setLaunchPath:@"/bin/sh"];
[task setArguments:args];
[task launch];
[NSNotificationCenter defaultCenter ] postNotificationName : @"Terminate" object : self ] ;
}
But if I add the required command line arguments to the args
array, the app terminates but doesn't relaunch.
I did something like this :
NSMutableArray *obj = [ NSMutableArray arrayWithObjects:@"-c", @"updated", nil ] ;
NSArray * args = [ NSArray arrayWithObjects:obj, [NSString stringWithFormat:@"sleep %f; open \"%@\"", seconds, [[NSBundle mainBundle] bundlePath]], nil ] ;
"updated" being the required argument to be passed to the new instance. What am I missing?
Any help is appreciated.