mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-22 11:14:00 +00:00
More robust technique for reading from pipeline
This commit is contained in:
parent
24b15c0f14
commit
97de91380c
|
@ -64,18 +64,28 @@
|
||||||
|
|
||||||
- (NSString*)getLineFromCommand:(NSString*)command
|
- (NSString*)getLineFromCommand:(NSString*)command
|
||||||
{
|
{
|
||||||
char line[1000];
|
char line[1000];
|
||||||
FILE * output = popen([command UTF8String], "r");
|
FILE * output = popen([command UTF8String], "r");
|
||||||
if (fgets(line, 1000, output)) {
|
NSString * outLine = nil;
|
||||||
size_t len = strlen(line);
|
for (int attempts=0; attempts<5; ++attempts)
|
||||||
if (len && line[len-1]=='\n') {
|
if (fgets(line, 1000, output)) {
|
||||||
line[len-1] = 0;
|
size_t len = strlen(line);
|
||||||
return [NSString stringWithUTF8String:line];
|
if (len && line[len-1]=='\n') {
|
||||||
}
|
line[len-1] = 0;
|
||||||
} else
|
outLine = [NSString stringWithUTF8String:line];
|
||||||
NSLog(@"Failed command: %@ %s (%d)\n", command, feof(output) ? "EOF" : "Error", errno);
|
}
|
||||||
|
} else if (feof(output))
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
clearerr(output);
|
||||||
|
|
||||||
|
if (!outLine)
|
||||||
|
NSLog(@"Failed command: %@ %s (%d)\n", command,
|
||||||
|
feof(output) ? "EOF" : "Error", errno);
|
||||||
|
|
||||||
pclose(output);
|
pclose(output);
|
||||||
return nil;
|
|
||||||
|
return outLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)lilypondVersion:(NSString *)path
|
- (NSString *)lilypondVersion:(NSString *)path
|
||||||
|
|
Loading…
Reference in New Issue
Block a user