Created
January 25, 2018 06:30
-
-
Save bakkiraju/ea2f70eb599e22b654e9025a1c23df6d to your computer and use it in GitHub Desktop.
Finding out if a shell script ran to completion using ObjC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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