Skip to content

Instantly share code, notes, and snippets.

@beelsebob
Forked from anonymous/gist:1329146
Created October 31, 2011 22:02
Show Gist options
  • Select an option

  • Save beelsebob/1329161 to your computer and use it in GitHub Desktop.

Select an option

Save beelsebob/1329161 to your computer and use it in GitHub Desktop.
NSString *currentDir = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/java"];
[task setCurrentDirectoryPath:currentDir];
[task setArguments:[NSArray arrayWithObjects:[NSString stringWithFormat:@"-Xmx%dM", [RamTextField intValue]], [NSString stringWithFormat:@"-Xms%dM", [RamTextField intValue]], @"-jar", [NSString stringWithFormat:@"%@/minecraft_server.jar", currentDir], nil]];
NSPipe *pipe = [NSPipe pipe];
[task setStandardError: pipe];//Return Error only
[task setStandardInput:[NSPipe pipe]];
NSFileHandle *file = [pipe fileHandleForReading];
[task launch];
NSData *data = [file readDataToEndOfFile];
NSString *output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"script returned: %@", output);
if ([self containsString:@"Unable to access jarfile" inThisString:[NSString stringWithFormat:@"%@", output]]){
NSAlert *msgBox = [[NSAlert alloc] init];
[msgBox setAlertStyle:2];
[msgBox setMessageText:@"Unable to find minecraft_server.jar in the current directory."];
[msgBox runModal];
}else{
NSAlert *msgBox2 = [[NSAlert alloc] init];
[msgBox2 setAlertStyle:1];
[msgBox2 setMessageText:@"Thanks to Jamesst20 ! Enjoy :)"];
[msgBox2 runModal];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment