Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSLog broken after call of NSTask and setStandardError



Hello,
I'm new to cocoa and obj c programming. Thanks to such great mailling lists like this one here, I have learned a lof during the last weeks. However here is something I cannot cope with:


Code:
--------

I use this cocoa method to execute shell commands and shell scripts form my cocoa app:
- (void)executeShellScript:(NSString*)path withArgs:(NSArray*)args {
NSLog(@"Testing NSLog: Entry");
NSString *fullpath = [path stringByExpandingTildeInPath];
NSFileManager *fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:fullpath]) {
NSTask *shellProcess = [[NSTask alloc] init];
NSPipe *errorPipe = [[NSPipe alloc] init];
[shellProcess setLaunchPath:fullpath];
[shellProcess setArguments:args];
[shellProcess setStandardError:errorPipe];
[shellProcess launch];
[shellProcess waitUntilExit];
NSData *result = [[errorPipe fileHandleForReading] readDataToEndOfFile];
if ([result length]>1) {
NSString *error = [[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding];
NSLog(error); //Normally I would show an error dialog with a NSTextView here
[error release];
}
[shellProcess release];
}
else {
NSString *error = [fullpath stringByAppendingString:@": File does not exist"];
NSLog(error); //Normally I would show an error dialog with a NSTextView here
}
NSLog(@"Testing NSLog: Exit");
}



Problem: -------

At the first glance: no problems! I can call shell commands, shell scripts and retrieve stderr from the shell and display this stuff in cocoa.
The probelm is:
- When I call above method e.g. with [self executeShellScript:@"/Users/siemoneit/Documents/LocationManager/heim/activate.sh" withArgs:args];, .i.e. I try to execute a shell script, NSLog gets broken, only outputs in the console "Testing NSLog: Entry" + "Hello" (=some ouput of the shell script via echo) and nothing more. Further NSLog ouput is lost totally. NSLog remains broken. You have to restart the app.
This is the shell script I call:
#!/bin/bash
echo Hello
exit 0


- When I call above method e.g. with [self executeShellScript:@"/bin/ls" withArgs:args]; i.e. with a shell command, everything works fine! NSLog doesn't get broken. Everything goes smoothly and nicely. The output is the console is as expected: "Testing NSLog:Entry" + the command output + "Testing NSLog: Exit". NSLog doesn't get broken.
What am I missing? What am I doing wrong? This drives me nuts...
Therefore: Any hint is highly appreciated!
Many thanks,
Oliver


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.