nstask

NSTask not picking up $PATH from the user's environment

I don't know why this method returns a blank string: - (NSString *)installedGitLocation { NSString *launchPath = @"/usr/bin/which"; // Set up the task NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:launchPath]; NSArray *args = [NSArray arrayWithObject:@"git"]; [task setArguments:args]; // Set the...

Using NSTask: app freezing after returning output

Hi I have the following code: - (IBAction)runTask:(id)sender { NSTask *proc; NSPipe *output; NSData *data; NSString *buffer; proc = [[NSTask alloc] init]; output = [[NSPipe alloc] init]; [proc setLaunchPath:@"/bin/sh"]; [proc setArguments:[NSArray arrayWithObjects: @"-c", @"/usr/bin/otool -L /Applicatio...

Using awk with NSTask

How would I use this awk command: awk 'NR>1{print $1}' string-to-modify with NSTask? I already tried setting /usr/bin/awk as the launch path, 'NR>1{print $1}' as an argument, then the string to modify as another argument but all I get is this: /usr/bin/awk: syntax error at source line 1 context is ' <<< /usr/bi...

Ensure a subprocess is dead in Cocoa

I'm writing an application that kicks off a subprocess running a simple web server. I am using NSTask and communicating with it with pipes, and everything seems more or less fine. However, if my program crashes, the subprocess is left alive and the next time I launch the app there is a conflict between the old subprocess and the new one....

Problems with NSTask in OS X 10.6 Snow Leopard

Has anyone else seen or heard of any issues with NSTask in 10.6? This code worked fine yesterday, and is not working today. NSTask *task = [converter task]; [task waitUntilExit]; NSLog(@"Task did complete"); The task does what it's supposed to do (I checked the output and it's fine), but the program will wait indefinitely at the wait...

Working around NSFileHandle NSTask blocking when passing large amounts of data

I've got a bit of code that handles exporting data from my application. It takes in an NSString full of XML and runs it through a PHP script to generate HTMl, RTF, etc. It works well unless a user has a large list. This is apparently due to it overrunning the 8k or so buffer of NSPipe. I worked around it (I think) in the readPip...

Converting shell script to Objective-C CLI

I am planning to convert a rather long shell script I have into an Objective C command line tool. I'm planning to use NSTask to run the shell commands (this is a large script, and it has several thousand copy/move/delete operations). My question is, will continually allocating and deallocating NSTask objects to run all these commands res...

NSTask returning HTTP Headers

I'm running /usr/bin/perl or /usr/bin/php via an NSTask and want to retrieve the HTTP headers of the program. I've properly formatted the environment (Perl requires env vars to be prefixed with HTTP_), but neither of the task are returning anything other than raw output. I've been through the documentation on NSTask and the man pages f...

NSTask or equivalent for iPhone

I've an open source project (gdal) that I want to compile and run as part of an iPhone app. I had been expecting to use NSTask but I see now that it was removed in OS 3.0. I've also seen elsewhere that running external applications, though this would be a resource in my app's bundle, is not allowed. Has anyone else found a way to run c...

Using NSTask with an NSPipe and a Perl script that spawns another process

I am running a Perl script within an NSTask object with it's output going into an NSPipe. I am using notifications to receive it's output periodically and update the GUI. The Perl script actually spawns other processes whose output doesn't seem to go into this pipe, but does appear in the debugger console and I can see them running ther...

Ignoring user input while waiting for a task - Objective-C

I have an app with a button 'convert'. When I click this button, the app starts a new process using NSTask and then greys out the button until the process finishes. My problem is, the app saves any clicks made by the user while it is waiting for the process to finish. So even though the button is grayed out, the user can click it and th...

Relaunching application via NSTask ignores LSMinimumSystemVersionByArchitecture

I'm running into an issue with relaunching my application on 10.5. In my Info.plist I have LSMinimumSystemVersionByArchitecture set so that the application will run in 64-bit for x86_64 and 32-bit on i386, ppc, and ppc64. I have a preference in the app that allows the user to switch between a Dock icon & NSStatusItem, and it prompts th...

Program structure regarding NSTask

Hi, I want to run an unknown amount (unknown at compile time) of NSTasks and I want to run an unknown amount (again, at compile time, max. 8) of them simultaneously. So basically I loop through a list of files, generate an NSTask, run it until the maximum of simultaneous tasks are ran and whenever one finishes another NSTask starts unti...

Saving System Profiler info in a .spx file using NSTask

In Cocoa, I am trying to implement a button, which when the user clicks on will capture the System profiler report and paste it on the Desktop. Code NSTask *taskDebug; NSPipe *pipeDebug; taskDebug = [[NSTask alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(taskFinished:) name:NSTaskDidTermi...

Use NSTask to ssh into another computer

Is there a way I can use NSTask to ssh into another computer (in this case a chumby) and run commands on that device? I also have a password on it. ...

How to open a document using an application launched via NSTask?

Hello world, I've grown tired of the built-in open Mac OS X command, mostly because it runs programs with your actual user ID instead of the effective user ID; this results in the fact sudo open Foo opens Foo with its associated application with your account instead of the root account, and it annoys me. So I decided to make some kind o...

[Cocoa] NSTask string encoding problem

Hi, In my program, I'm grep-ing via NSTask. For some reason, sometimes I would get no results (even though the code was apparently the same as the command run from the CLI which worked just fine), so I checked through my code and found, in Apple's documentation, that when adding arguments to an NSTask object, "the NSTask object converts...

[Cocoa] Can't find leak in my code.

Hi, I've been spending the last few hours trying to find the memory leak in my code. Here it is: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; expression = [expression stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; // expression is an NSString object. NSArray *argument...

NSNotification and Multithreading

I'm trying to get the notification NSTaskDidTerminateNotification in my multithreaded app but I can't get it working. It does seem to work when I tested it on a single threaded app. In init I have [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(taskDidEnd:) name: NSTaskDidTerminateNotification object: myTask];...

sending control+c (SIGINT) to NSPIPE in objective-c

Hello, I am trying to terminate an openvpn task, spawned via NSTask. My question: Should I send ctrl+c (SIGINT) to the input NSPipe for my NSTask? inputPipe = [NSPipe pipe]; taskInput = [inputPipe fileHandleForWriting]; NSString dataString = @"\cC"; [taskInput writeData:[dataString dataUsingEncoding: [NSString defaultCStringEncoding]...