nspipe

How can I tell when a FileHandle has nothing left to be read?

此生再无相见时 提交于 2020-01-04 04:13:06
问题 I'm trying to use a Pipe's fileHandleForReading's readabilityHandler to read both the standardOutput and standardError of a Process. However, the moment the terminationHandler is called is actually before the moment my readabilityHandler is called for the first time. I'm not sure why the process does this, but it means I'm not getting all the data, because I assume process termination means all output has been flushed to the pipe. Since this isn't the case, is there a way for me to tell when

Using NSTask and NSPipe causes 100% CPU usage

百般思念 提交于 2019-12-22 04:39:21
问题 I'm trying to run a simple bash script using NSTask and direct the output to a text view. Once the task is executed, the CPU usage of my app is 100%, even though it's a simple echo (for now). I created a completely fresh project to isolate the issue: @interface AppDelegate () @property (nonatomic) NSTask *task; @property (nonatomic) NSPipe *pipe; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.pipe = [NSPipe pipe]; self.pipe

How to use NSTask run terminal commands in loop in consistent environment?

蹲街弑〆低调 提交于 2019-12-21 06:27:18
问题 I want to use NSTask to simulate the Terminal to run commands. The codes as follows. It can get input in loop and return the process output. int main(int argc, const char * argv[]) { @autoreleasepool { while (1) { char str[80] = {0}; scanf("%s", str); NSString *cmdstr = [NSString stringWithUTF8String:str]; NSTask *task = [NSTask new]; [task setLaunchPath:@"/bin/sh"]; [task setArguments:[NSArray arrayWithObjects:@"-c", cmdstr, nil]]; NSPipe *pipe = [NSPipe pipe]; [task setStandardOutput:pipe];

Swift NStask function

你说的曾经没有我的故事 提交于 2019-12-13 11:20:48
问题 I'm a complete swift noob. Using this code in xcode I get the result I need. I created a command line binary "menubar" that takes several arguments. I normally run it in the terminal "/bin/menubar getip", "/bin/menubar/getuser". I want to create a function based on the following working code. import Cocoa import Foundation var task:NSTask = NSTask() var pipe:NSPipe = NSPipe() task.launchPath = "/bin/menubar" task.arguments = ["getip"] task.standardOutput = pipe task.launch() var handle = pipe

why waitForDataInBackgroundAndNotify doesn't work with the real time monitor with more than 1 argument?

我的梦境 提交于 2019-12-12 01:34:55
问题 I have found the following code from one of the API, and I'm trying to use it to do a real time monitoring of vm_stat 1: BOOL terminated = NO; -(void)realTimeMonitor { NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/bin/bash"]; [task setArguments:[NSArray arrayWithObjects:@"-c", @"/usr/bin/vm_stat 1", nil]]; //works fine // [task setArguments:[NSArray arrayWithObjects:@"-c", @"/usr/bin/vm_stat 1 | /usr/bin/awk '{print $1}'", nil]]; not working NSPipe *pipe = [NSPipe pipe]; NSPipe

Can someone help me spot a leak in this NSPipe/NSFileHandle code?

我的未来我决定 提交于 2019-12-11 10:59:50
问题 So I'm having this issue where once this NSFileHandle/NSPipe gets triggered... my CPU use and memory start going crazy. Problem is I'm finding it hard to find this leak. Any advice or help is appreciated. Cheers. .h NSTask *task; NSPipe *pipe; NSFileHandle *fileHandle; @property (weak) IBOutlet NSTextField *commandInputTextField; @property (unsafe_unretained) IBOutlet NSTextView *nsTastOutput; @property (weak) IBOutlet NSButton *useOutputSwitch; .m - (id)init { [[NSNotificationCenter

NSTask/NSPipe read from Unix command

删除回忆录丶 提交于 2019-12-06 01:59:51
问题 I am writing a Cocoa application which needs to execute a UNIX program and read its output, line by line, as they are produced. I set up a NSTask and NSPipe as such: task = [[NSTask alloc] init]; pipe = [NSPipe pipe]; [task setStandardOutput:pipe]; //... later ... [task setArguments:...]; [task setLaunchPath:@"..."]; [task launch]; handle = [[task fileHandleForReading] retain]; The command does not terminate until the program tells it to do so with [task terminate] . I have tried several

Using NSTask and NSPipe causes 100% CPU usage

十年热恋 提交于 2019-12-05 05:02:50
I'm trying to run a simple bash script using NSTask and direct the output to a text view. Once the task is executed, the CPU usage of my app is 100%, even though it's a simple echo (for now). I created a completely fresh project to isolate the issue: @interface AppDelegate () @property (nonatomic) NSTask *task; @property (nonatomic) NSPipe *pipe; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.pipe = [NSPipe pipe]; self.pipe.fileHandleForReading.readabilityHandler = ^(NSFileHandle *h) { NSLog(@"Read: %@", [h readDataToEndOfFile]); }

NSTask/NSPipe read from Unix command

耗尽温柔 提交于 2019-12-04 05:21:48
I am writing a Cocoa application which needs to execute a UNIX program and read its output, line by line, as they are produced. I set up a NSTask and NSPipe as such: task = [[NSTask alloc] init]; pipe = [NSPipe pipe]; [task setStandardOutput:pipe]; //... later ... [task setArguments:...]; [task setLaunchPath:@"..."]; [task launch]; handle = [[task fileHandleForReading] retain]; The command does not terminate until the program tells it to do so with [task terminate] . I have tried several methods of reading from the handle, such as -readInBackgroundAndNotify , while([(data = [handle

How to use NSTask run terminal commands in loop in consistent environment?

◇◆丶佛笑我妖孽 提交于 2019-12-03 22:30:54
I want to use NSTask to simulate the Terminal to run commands. The codes as follows. It can get input in loop and return the process output. int main(int argc, const char * argv[]) { @autoreleasepool { while (1) { char str[80] = {0}; scanf("%s", str); NSString *cmdstr = [NSString stringWithUTF8String:str]; NSTask *task = [NSTask new]; [task setLaunchPath:@"/bin/sh"]; [task setArguments:[NSArray arrayWithObjects:@"-c", cmdstr, nil]]; NSPipe *pipe = [NSPipe pipe]; [task setStandardOutput:pipe]; [task launch]; NSData *data = [[pipe fileHandleForReading] readDataToEndOfFile]; [task waitUntilExit];