• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSLog broken after call of NSTask and setStandardError
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSLog broken after call of NSTask and setStandardError


  • Subject: NSLog broken after call of NSTask and setStandardError
  • From: "Oliver Siemoneit" <email@hidden>
  • Date: Tue, 15 Jan 2008 22:38:33 +0100

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSLog broken after call of NSTask and setStandardError
      • From: Thomas Engelmeier <email@hidden>
    • Re: NSLog broken after call of NSTask and setStandardError
      • From: "Hamish Allan" <email@hidden>
  • Prev by Date: Re: NSPopupButton on Toolbar with Image instead?
  • Next by Date: Re: NSWindow and autorelease with dynamic binary
  • Previous by thread: Fwd: CAAnimation working with float, but not with int?
  • Next by thread: Re: NSLog broken after call of NSTask and setStandardError
  • Index(es):
    • Date
    • Thread