nstask

NSTask Question

醉酒当歌 提交于 2019-12-06 08:45:25
I'm trying to get my NSTask to unzip a file for me. This works fine if the path has no spaces, but when it does, it can't find any of the files. I can't hardcode the " signs because I'm storing the zip file in a temporary folder, which is assigned by the system. Does anyone know how to achieve this? Here's my code: NSTask*task = [[NSTask alloc] init]; [task setLaunchPath:@"/usr/bin/unzip"]; NSArray*arguments = [NSArray arrayWithObjects:zipPath,@"-d",path,nil]; [task setArguments:arguments]; [task launch]; [task release]; Having a space in the argument does not look like your problem - note

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

NSTask launch path not accessible. Works in Xcode. Error shown out of XCode

牧云@^-^@ 提交于 2019-12-06 01:25:49
问题 Ok. There are several questions on stack overflow about this. This question was the only question comes closest to mines, but it uses notifications. The code is very simple. Create a new empty Mac OSX project and just paste the following code in the applicationDidFinishLaunching: method. It supposed to get the path of any executable file (in this case GIT). NSTask *aTask = [[NSTask alloc] init]; NSPipe *outputPipe = [NSPipe pipe]; NSPipe *errorPipe = [NSPipe pipe]; [aTask setStandardOutput:

Trying to use cydia libraries: NSTask on Jailbroken iphone crashes with Segmentation fault: 11

大城市里の小女人 提交于 2019-12-05 18:50:28
I want to run dpkg ( or any other binary library files from cydia in the /bin or /usr/bin directories) from a GUI app with an icon, like mobileterminal, ifile, myfile, cydia, alertscript, and so many others can. How do they accesses the libraries? This code works, and the stdout of the process is printed in nslog but then it immediately crashes with Segmentation fault: 11. this is in my viewdidload function. This DOES NOT OCCUR IN THE SIMULATOR, only my iPhone 4. weird. have tried running as both mobile and root. the app is under /Applications folder. Here's my code. EDIT: I'm using the snow

How to safely use [NSTask waitUntilExit] off the main thread?

耗尽温柔 提交于 2019-12-05 16:27:36
I have a multithreaded program that needs to run many executables at once and wait for their results. I use [nstask waitUntilExit] in an NSOperationQueue that runs it on non-main thread (running NSTask on the main thread is completely out of the question). My program randomly crashes or runs into assertion failures, and the crash stacks always point to the runloop run by waitUntilExit , which executes various callbacks and handlers, including—IMHO incorrectly—KVO and bindings updating the UI , which causes them to run on non-main thread (It's probably the problem described by Mike Ash ) How

Terminate an NSTask and its children

给你一囗甜甜゛ 提交于 2019-12-05 10:07:51
I'm using NSTask to execute a series of long running commands like so: commandToRun = @"command 1;command2"; NSArray *arguments = [NSArray arrayWithObjects: @"-c", commandToRun, nil]; self.task = [[NSTask alloc] init]; [self.task setLaunchPath: @"/bin/sh"]; [self.task setArguments: arguments]; [self.task launch]; This creates a process for the shell, and a child process for whichever command is running at the time (command 1 or command 2). If I kill the task with [self.task terminate] it only kills the parent process. Is there a way to identify and kill the children too? It's not exactly

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

How to embed an executable in my project

岁酱吖の 提交于 2019-12-04 23:58:08
问题 I would like to embed a command-line executable in my Xcode/Cocoa project, to then start it with NSTask. Which path should I use in the setLaunchPath ? Thanks ! 回答1: you should add it to your resources folder. Then, in runtime, read the app's resource bundle path, and append the name of the executable (including subfolders if you add it to a folder inside the resource bundle) For instance: NSString *execPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"binaryname"]

How to use a determinate NSProgressIndicator to check on the progress of NSTask? - Cocoa

家住魔仙堡 提交于 2019-12-04 23:13:52
问题 What I have is NSTask running a long premade shell script and I want the NSProgressIndicator to check on how much is done. I've tried many things but just can't seem to get it to work. I know how to use it if the progress bar is indeterminate but i want it to load as the task goes on. Here is how I am running the script: - (IBAction)pressButton:(id)sender { NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/bin/sh"]; [task setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle

NSTask blocking the main thread

纵饮孤独 提交于 2019-12-04 23:05:34
问题 I'm using NSTask, but when I launch the task it blocks the main thread (so I can't update it) until the task ends. This is my code: NSString *hostsforping = @"google.es"; pingdata = [[NSTask alloc] init]; [pingdata setLaunchPath: @"/sbin/ping"]; NSArray *pingargs; pingargs = [NSArray arrayWithObjects: @"-c 5", hostsforping, nil]; [pingdata setArguments: pingargs]; NSPipe *pingpipe; pingpipe = [NSPipe pipe]; [pingdata setStandardOutput: pingpipe]; NSFileHandle *pingfile; pingfile = [pingpipe