Skip to main content
edited tags
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Separated the code asking to be reviewed from the example usage code (it was confusing me)
Source Link

This is my first real Cocoa app that I am writing. The first version of this app was just one long applescript. So in my app auto git, I have an NSTask instead of Tell terminal. My code looks like this:

    [self runScript:dirPath:@"add" :@"*" :nil];
    [self runScript:dirPath:@"commit" :@"-m" :commitText];
    [self runScript:dirPath:@"push" :@"origin" :@"HEAD"];

-(void) runScript:(NSString *) path:(NSString* )cmd1:(NSString *) cmd2:(NSString *) cmd3{
    
    NSTask *aTask = [[NSTask alloc] init];
    
    NSPipe *pipe;
    pipe = [NSPipe pipe];
    [aTask setStandardOutput: pipe];
    
    NSFileHandle *file;
    file = [pipe fileHandleForReading];
    
    NSArray* args = [NSArray arrayWithObjects:cmd1,cmd2,cmd3, nil];
    [aTask setArguments:args];
    [aTask setCurrentDirectoryPath:path];
    [aTask setLaunchPath:@"/usr/local/git/bin/git"];
    [aTask setArguments:args];
    [aTask launch];
    
    [finished setStringValue:@"finished"];

}

Example usage:

[self runScript:dirPath:@"add" :@"*" :nil];
[self runScript:dirPath:@"commit" :@"-m" :commitText];
[self runScript:dirPath:@"push" :@"origin" :@"HEAD"];
 

Is there a better way to do this? And what about errors? How to I let the user take care of custom errors?

All help appreciated.

This is my first real Cocoa app that I am writing. The first version of this app was just one long applescript. So in my app auto git, I have an NSTask instead of Tell terminal. My code looks like this:

    [self runScript:dirPath:@"add" :@"*" :nil];
    [self runScript:dirPath:@"commit" :@"-m" :commitText];
    [self runScript:dirPath:@"push" :@"origin" :@"HEAD"];

-(void) runScript:(NSString *) path:(NSString* )cmd1:(NSString *) cmd2:(NSString *) cmd3{
    
    NSTask *aTask = [[NSTask alloc] init];
    
    NSPipe *pipe;
    pipe = [NSPipe pipe];
    [aTask setStandardOutput: pipe];
    
    NSFileHandle *file;
    file = [pipe fileHandleForReading];
    
    NSArray* args = [NSArray arrayWithObjects:cmd1,cmd2,cmd3, nil];
    [aTask setArguments:args];
    [aTask setCurrentDirectoryPath:path];
    [aTask setLaunchPath:@"/usr/local/git/bin/git"];
    [aTask setArguments:args];
    [aTask launch];
    
    [finished setStringValue:@"finished"];

}
 

Is there a better way to do this? And what about errors? How to I let the user take care of custom errors?

All help appreciated.

This is my first real Cocoa app that I am writing. The first version of this app was just one long applescript. So in my app auto git, I have an NSTask instead of Tell terminal. My code looks like this:

-(void) runScript:(NSString *) path:(NSString* )cmd1:(NSString *) cmd2:(NSString *) cmd3{
    
    NSTask *aTask = [[NSTask alloc] init];
    
    NSPipe *pipe;
    pipe = [NSPipe pipe];
    [aTask setStandardOutput: pipe];
    
    NSFileHandle *file;
    file = [pipe fileHandleForReading];
    
    NSArray* args = [NSArray arrayWithObjects:cmd1,cmd2,cmd3, nil];
    [aTask setArguments:args];
    [aTask setCurrentDirectoryPath:path];
    [aTask setLaunchPath:@"/usr/local/git/bin/git"];
    [aTask setArguments:args];
    [aTask launch];
    
    [finished setStringValue:@"finished"];

}

Example usage:

[self runScript:dirPath:@"add" :@"*" :nil];
[self runScript:dirPath:@"commit" :@"-m" :commitText];
[self runScript:dirPath:@"push" :@"origin" :@"HEAD"];
 

Is there a better way to do this? And what about errors? How to I let the user take care of custom errors?

All help appreciated.

Source Link

NSTask with Git

This is my first real Cocoa app that I am writing. The first version of this app was just one long applescript. So in my app auto git, I have an NSTask instead of Tell terminal. My code looks like this:

    [self runScript:dirPath:@"add" :@"*" :nil];
    [self runScript:dirPath:@"commit" :@"-m" :commitText];
    [self runScript:dirPath:@"push" :@"origin" :@"HEAD"];

-(void) runScript:(NSString *) path:(NSString* )cmd1:(NSString *) cmd2:(NSString *) cmd3{
    
    NSTask *aTask = [[NSTask alloc] init];
    
    NSPipe *pipe;
    pipe = [NSPipe pipe];
    [aTask setStandardOutput: pipe];
    
    NSFileHandle *file;
    file = [pipe fileHandleForReading];
    
    NSArray* args = [NSArray arrayWithObjects:cmd1,cmd2,cmd3, nil];
    [aTask setArguments:args];
    [aTask setCurrentDirectoryPath:path];
    [aTask setLaunchPath:@"/usr/local/git/bin/git"];
    [aTask setArguments:args];
    [aTask launch];
    
    [finished setStringValue:@"finished"];

}
 

Is there a better way to do this? And what about errors? How to I let the user take care of custom errors?

All help appreciated.