Skip to content

Instantly share code, notes, and snippets.

@bakkiraju
Created January 25, 2018 06:30
Show Gist options
  • Save bakkiraju/ea2f70eb599e22b654e9025a1c23df6d to your computer and use it in GitHub Desktop.
Save bakkiraju/ea2f70eb599e22b654e9025a1c23df6d to your computer and use it in GitHub Desktop.
Finding out if a shell script ran to completion using ObjC
NSBundle* myBundle = [NSBundle mainBundle];
NSString* myScript = [myBundle pathForResource:@"isScriptRunning"
ofType:@"sh"
inDirectory:@"ScriptsDir"];
NSTask *task;
task = [[NSTask alloc] init];
#if !__has_feature(objc_arc)
[task autorelease];
#endif
[task setLaunchPath: @"/bin/sh"];
NSArray *arguments;
arguments = @[
myScript,
];
[task setArguments: arguments];
[task setStandardOutput: [NSPipe pipe]];
[task setStandardInput:[NSPipe pipe]];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *output;
output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
Debug ("script returned:\n%s", string.UTF8String);
BOOL installerRunning = output.length > 0;
return installerRunning;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment