nstask

Run a terminal command in a Mac app with Swift Xcode

为君一笑 提交于 2019-12-04 21:24:02
问题 I am trying to run a terminal command in a Mac app that I am developing. The terminal command is: sudo sysctl -w net.inet.tcp.delayed_ack=0 I have tried using NSTask but it seems that I am doing something wrong every time. I just want to run this command and print the output. Thank you for your attention. PS. here is what my current code looks like (thanks to your replies): let task = NSTask() task.launchPath = "/usr/sbin/sysctl" task.arguments = ["-w", "net.inet.tcp.delayed_ack=0"] let pipe

Get Notification of task progress from NSTask

痴心易碎 提交于 2019-12-04 17:10:31
Any body have idea about getting notification from NSTask while NSTask is executed. I am unzipping a zip file using NSTask and need to show the unzip data progress in a NSProgressBar. I don't found any idea for doing such task.So that i show the value in progress bar. Need help for doing this task. Thanks in advance. Use NSFileHandleReadCompletionNotification , NSTaskDidTerminateNotification notifications. task=[[NSTask alloc] init]; [task setLaunchPath:Path]; NSPipe *outputpipe=[[NSPipe alloc]init]; NSPipe *errorpipe=[[NSPipe alloc]init]; NSFileHandle *output,*error; [task setArguments:

Strange GDB behaviour once application is deployed to a jailbroken iPhone

北城以北 提交于 2019-12-04 17:04:06
Im trying to make an application which sends commands to GDB via NSTask and directs the output to the UITextView. It works well on the Mac (iOS Simulator). However, when deployed to the actual device (iPhone), it does not display any registers after the command "info registers" The code is as such : - (void)viewDidLoad { self.title = @"GDB"; NSLog(@"Pid for GDB execution is :%@", pid); UIBarButtonItem *btnClicked = [[UIBarButtonItem alloc] initWithTitle:@"Commands" style:UIBarButtonItemStyleBordered target:self action:@selector(btnClicked:)]; self.navigationItem.rightBarButtonItem = btnClicked

Unable to get intermediate output from NSTask's stdout?

浪尽此生 提交于 2019-12-04 06:22:00
问题 I have written an NSTask async exec method for a simple python script. When then python script just prints to stdout, all is fine. When there is a raw_input in there (expecting input from the user), it sure gets the input fine, but it does NOT print the data BEFORE raw_input . What's going on? - (NSString*)exec:(NSArray *)args environment:(NSDictionary*)env action:(void (^)(NSString*))action completed:(void (^)(NSString*))completed { _task = [NSTask new]; _output = [NSPipe new]; _error =

NSTask, command line tools and root

半世苍凉 提交于 2019-12-04 06:04:31
I'm working on an app that needs to use dd (I do this with a shell script in the app bundle, that collects parameters from the app itself, makes some checks and then launches dd). To make this operation I need to call dd with root, and I already looked at several solutions on StackOverflow. The simplest to implements seemed to me this one http://www.sveinbjorn.org/STPrivilegedTask Problem is that my NSTask makes some complex read/write operations (not present in STPrivilegedTask) and does not need to be all privileged. So I wrote a small helper tool in c that calls my script with correct

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 work around NSTask calling -[NSString fileSystemRepresentation] for arguments

爷,独闯天下 提交于 2019-12-04 03:31:32
问题 It seems that NSTask calls -[NSString fileSystemRepresentation] to encode values for each of the arguments you give it. This can become a problem in some situations due to the fact that -fileSystemRepresentation encodes using decomposed unicode forms : for example, the a-umlaut (ä) would be encoded as U+0061 (Latin small letter a) and U+0308 (Combining diaeresis), as opposed to U+00E4 (Latin small letter a with diaeresis). The -UTF8String method, on the other hand, seems to do the opposite. I

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];

NSTask and NSPipe example to comunicate with the command line objective-c

 ̄綄美尐妖づ 提交于 2019-12-03 16:13:05
Can someone show a quick example on how to use NSTask and NSPipe in conjunction to do this: Charlie AI - run through terminal to comunicate with the AI I want to create a nice GUI for it using xcode and objective c. I want to have 2 NSTextFields for the charlie's response and user input. Then have a send button to send the user input to the command line, then get the charlie's response and post it in the NSTextField. I can handle the GUI stuff (NSTextField, ect.) But I need help with the objective-c coding part. Thanks! Elijah Apple have some nice sample code that shows how to do most of that.

Getting data from the nstask - communicating with command line - objective c

有些话、适合烂在心里 提交于 2019-12-03 16:10:42
问题 I know how to send data to the task: NSData *charlieSendData = [[charlieImputText stringValue] dataUsingEncoding:NSUTF8StringEncoding]; [[[task standardInput] fileHandleForWriting] writeData:charlieSendData]; But how do I get what the task responds with?? Elijah 回答1: Give an NSPipe or an NSFileHandle as the task's standardOutput , and read from that. NSTask * list = [[NSTask alloc] init]; [list setLaunchPath:@"/bin/ls"]; [list setCurrentDirectoryPath:@"/"]; NSPipe * out = [NSPipe pipe]; [list