nstask

NSTask or NSThread?

I have some code that is attached to an NSTimer. Around 5 times every second, it interacts with another application (by emulating keystrokes) and when appropriate spits out an NSNotification, that is handled by another piece of code. While the timer code is running, the UI is unresponsive, so I can't include a 'stop' button that halts ...

NSTask executed only once

I'm having trouble executing different NSTask's. Same launchPath, different arguments. I have a class who's instances administer own NSTask objects and depending on arguments those instances were initialized with - dependent NSTask object is being created. I have two initializers: // Method for finished task - (void)taskFinished:(NSNoti...

Terminating suspended NSTask.

Hi, If I terminate (or interrupt) a suspended NSTask, then it still shows up in activity monitor. It isn't running because the CPU is 0% but it's still taking up memory. Is there a work around? ...

Can NSTask safely be used outside the main thread?

Yesterday I read somewhere that NSTask isn't thread safe and that bothers me a lot, because I'm running a NSTask within a NSThread and is so far not experiencing any threading issues with it. My code is organized like this A: main thread -> B: worker thread -> C: worker task C: The worker task is a commandline program. B: The worker t...

Command Line arguments from a Cocoa App

Hey guys, I know there is a lot of info out there on how to do this, but I was wondering if using NSTask is the best way to call command line arguments from a Cocoa App. Also, if I wanted to use something like "dns-sd ..." (something that doesn't end until interrupted or killed), would calling a kill on it using NSTask be the best way t...

Detecting whether a process starts and finishes with notifications in cocoa

Hi everyone, I was wondering if there was a way that I could get notifications of when a system process from /usr/sbin starts and finishes. Is it possible to attach NSTask to the running process without launching a new one? Preferably without polling please :! ...

Cocoa NSTask help

Hey guys, I need a bit of help with NSTask. Also, I am new to Cocoa / Obj-C programming, so please bear with me. I am trying to make a directory. Then, remove it. So here is what I have so far: NSLog (@"START"); NSTask *task; task = [[NSTask alloc] init]; [task setLaunchPath: @"/bin/mkdir"]; NSArray *arguments; arguments = [NSArray a...

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

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 t...

NSTask setLaunchPath Objective-C Cocca

Hello, This is a very simple question. I have a script in the same folder as the Cocoa app. I can't seem to set the path to it properly for setLaunchPath for NSTask. Help please. I have a folder called Project. Inside of it, exist multiple folders but only two we care about: Classes (the source files for the Cocoa app are here) and Rub...

NSTask Until Interrupted Command in Cocoa / Objective-C

Hello, I am trying to use NSTask on to run an ASR Multicast Stream, a Ruby Server Script, etc. Basically, I'm trying to run tasks with NSTask that do not finish running until interrupted, but the problem is that I can't get the NSTask to run in the background. So it ends up just running and holding up the rest of my program. Any help? ...

NSTask launch path not accessible

Hello, I am using the following code in my Cocoa project to call a script I made. The script is in the same folder as the project and even shows up under the "Resources" folder in XCode. The proper path is found, but it still says that the path is not accessible. Help please. NSBundle *mainBundle=[NSBundle mainBundle]; NSString *path=[...

NSTask sending an argument through /bin/sh or /bin/bash problem Cocoa Objective-C

Hello, Basically I've passed a script in the terminal through /bin/bash "[path]" or /bin/sh "[path]", and I've passed commands in a terminal through /bin/bash -c "[command]" or /bin/sh -c "[command]". Both ways work properly. But in my Cocoa App, when I try to do the exact same thing with NSTask (using /bin/bash or /bin/sh), the app see...

Creating a GUI for a command-line utility using Cocoa

I'm looking for a way to create a GUI (using Cocoa) to make a command-line utility more accessible to some of my colleagues. If you use NSTask to execute/start the utility, can you then simply use another NSTask to execute the next command (using the utility launched in the previous step)? Does it use the same session, in other words? I ...

Why does an autoreleased NSTask block the runloop on an NSOperation thread indefinitely?

I've run into an while trying to launch an NSTask from inside an NSOperation. Here's a very simple app I've put together to showcase the problem. When you click the button, an NSOperation is queued. It sets up an NSRunLoop, and calls a method which invokes an NSTask. The task is really simple- it just launches /bin/sleep for two seconds...

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

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 ...

NSTask NSPipe - objective c command line help

Here is my code: task = [[NSTask alloc] init]; [task setCurrentDirectoryPath:@"/applications/jarvis/brain/"]; [task setLaunchPath:@"/applications/jarvis/brain/server.sh"]; NSPipe * out = [NSPipe pipe]; [task setStandardOutput:out]; [task launch]; [task waitUntilExit]; [task release]; NSFileHandle * read = [out fileHandleForReading]; ...

Code problem - objective c - waiting for string value to appear in string value

task = [NSTask new]; [task setLaunchPath:@"/bin/sh"]; [task setArguments:[NSArray arrayWithObject:@"/applications/jarvis/brain/server.sh"]]; [task setCurrentDirectoryPath:@"/"]; NSPipe *outputPipe = [NSPipe pipe]; [task setStandardInput:[NSPipe pipe]]; [task setStandardOutput:outputPipe]; [task launch]; NSMutableString *outputString =...

I can't see the output of NSTask - objective-c JAVA

Here is my code: NSTask *setupTask = [NSTask new]; [setupTask setLaunchPath:@"/bin/sh"]; [setupTask setArguments:[NSArray arrayWithObject:@"/applications/jarvis/brain/server.sh"]]; [setupTask setCurrentDirectoryPath:@"/"]; NSPipe *outputPipeSetup = [NSPipe pipe]; [setupTask setStandardInput:[NSPipe pipe]]; [setupTask setStandardOutput:o...

Example of NSTask performing complex pipelines

Can someone post code to show this? Elijah ...

How would I run an .sh file using NSTask and get its output?

I need to run an .sh file and get its output. I need to see the setup of the file as well. The .sh file simply runs a java app through terminal. Any ideas? I'm truly stuck on this..... Elijah The server.sh file: echo Starting Jarvis Program D. ALICE_HOME=. SERVLET_LIB=lib/servlet.jar ALICE_LIB=lib/aliceserver.jar JS_LIB=lib/js.jar ...