Hallo zusammen,
ich bin neu hier und auch erst seit ein paar Wochen mit Obj C und Cocoa unterwegs. Hab schon einiges gelernt, v.a. weil es so tolle Foren gibt wie dieses hier. Weshalb dieser Code jedoch nicht geht, versteh ich nicht.
Was geht nicht? Nach der Ausführung diese Codes ist NSLog kaputt, gibt nichts mehr in der Konsole aus. Irgendwie scheint NSLog der stderr verloren gegangen zu sein. Was mach ich hier falsch? Ich release doch die Pipe wieder! Auch ist's ja nur der stderr für den Task, den ich setze.
- (void)executeShellScript:(NSString*)path withArgs:(NSArray*)args {
NSLog(@"Entry");
NSString *fullpath = [path stringByExpandingTildeInPath];
NSFileManager *fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:fullpath]) {
NSTask *shellProcess = [[NSTask alloc] init];
NSPipe *errorPipe = [NSPipe pipe];
//NSPipe *errorPipe = [[NSPipe alloc] init];
[shellProcess setLaunchPath:fullpath];
[shellProcess setArguments:args];
[shellProcess setStandardError:errorPipe];
[shellProcess launch];
NSData *result = [[errorPipe fileHandleForReading] readDataToEndOfFile];
if ([result length]>1) {
NSString *error = [[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding];
[self showErrMsg:error];
[error release];
}
NSLog(@"Pipe open");
//[errorPipe release];
[shellProcess release];
NSLog(@"Pipe and task closed");
}
else {
NSString *error = [fullpath stringByAppendingString:@": File does not exist"];
[self showErrMsg:error];
}
NSLog(@"Cheerio Miss Sophie");
}
NSLog gibt nur "Entry" aus. Dann ist Schluß. Die Applikation muß neu gestartet werden, damit es wieder funktioniert.
Eine Idee? Die Doku für NSTask setStandardError ist ein bißchen arg kryptisch für einen Anfänger: If file is an NSPipe object, launching the receiver automatically closes the read end of the pipe in the current task. Don’t create a handle for the pipe and pass that as the argument, or the read end of the pipe won’t be closed automatically. ???
ich bin neu hier und auch erst seit ein paar Wochen mit Obj C und Cocoa unterwegs. Hab schon einiges gelernt, v.a. weil es so tolle Foren gibt wie dieses hier. Weshalb dieser Code jedoch nicht geht, versteh ich nicht.
Was geht nicht? Nach der Ausführung diese Codes ist NSLog kaputt, gibt nichts mehr in der Konsole aus. Irgendwie scheint NSLog der stderr verloren gegangen zu sein. Was mach ich hier falsch? Ich release doch die Pipe wieder! Auch ist's ja nur der stderr für den Task, den ich setze.
- (void)executeShellScript:(NSString*)path withArgs:(NSArray*)args {
NSLog(@"Entry");
NSString *fullpath = [path stringByExpandingTildeInPath];
NSFileManager *fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:fullpath]) {
NSTask *shellProcess = [[NSTask alloc] init];
NSPipe *errorPipe = [NSPipe pipe];
//NSPipe *errorPipe = [[NSPipe alloc] init];
[shellProcess setLaunchPath:fullpath];
[shellProcess setArguments:args];
[shellProcess setStandardError:errorPipe];
[shellProcess launch];
NSData *result = [[errorPipe fileHandleForReading] readDataToEndOfFile];
if ([result length]>1) {
NSString *error = [[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding];
[self showErrMsg:error];
[error release];
}
NSLog(@"Pipe open");
//[errorPipe release];
[shellProcess release];
NSLog(@"Pipe and task closed");
}
else {
NSString *error = [fullpath stringByAppendingString:@": File does not exist"];
[self showErrMsg:error];
}
NSLog(@"Cheerio Miss Sophie");
}
NSLog gibt nur "Entry" aus. Dann ist Schluß. Die Applikation muß neu gestartet werden, damit es wieder funktioniert.
Eine Idee? Die Doku für NSTask setStandardError ist ein bißchen arg kryptisch für einen Anfänger: If file is an NSPipe object, launching the receiver automatically closes the read end of the pipe in the current task. Don’t create a handle for the pipe and pass that as the argument, or the read end of the pipe won’t be closed automatically. ???