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

前端 未结 4 1198
粉色の甜心
粉色の甜心 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:34

    The problem is that you aren't emptying the output buffers of the task. You can't simply launch a task and waitUntilDone unless the task also emits an extremely small amount of data.

    waitUntilDone will obviously not work at all with a task that never exits.

    For a task that emits any quantity of output, you need to set it up such that the output is read as it is generated. Typically, you use readInBackgroundAndNotify or a variant therein.

    In any case, the top of the class description for NSTask has both links to the conceptual guide and to a series of examples that cover this.

提交回复
热议问题