Execute shell script from cocoa (obj.c) with response

前端 未结 4 1173
粉色の甜心
粉色の甜心 2021-01-06 04:57

I have something like:

- (NSString *)unixSinglePathCommandWithReturn:(NSString *)command
{
NSPipe *newPipe = [NSPipe pipe];
NSFileHandle *readHandle = [newPi         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-06 05:16

    Hey, Kukosk. There’s a comment on CocoaDev about NSLog() issues when running an NSTask. The fix is to set a pipe for stdin before launching the task:

    [task setStandardInput:[NSPipe pipe]];
    

    If you’re relying on NSLog() only to check whether the task has run, this might fix your problem. Alternatively, you could try to present output in your GUI instead of using NSLog().

提交回复
热议问题