这是我的代码:
-(void)startTask{
NSString * cmd = @"/bin/sh";
pty_ = [[PseudoTTY alloc] init];
NSTask * task = [[NSTask alloc] init];
[task setStandardInput:[pty_ slaveFileHandle]];
[task setStandardOutput:[pty_ slaveFileHandle]];
[task setStandardError:[pty_ slaveFileHandle]];
[task setCurrentDirectoryPath:[@"~" stringByExpandingTildeInPath]];
[task setLaunchPath:@"/bin/sh /applications/jarvis/brain/server.sh"];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(didRead:)
name:NSFileHandleReadCompletionNotification
object:[pty_ masterFileHandle]];
[[pty_ masterFileHandle] readInBackgroundAndNotify];
[task launch];
[self insertText:
[NSString stringWithFormat:@"Started %@ on terminal %@", cmd, [pty_ name]]];
}
但是,而不是这个,我需要它来启动一个 SH 文件:/applications/brain/server.sh
我很困惑....
有人可以帮我写代码吗?
谢谢,以利亚