Questions tagged [nstask]

NSTask Class on OS X API , lets you run another program as a subprocess and monitor that program’s execution

452 questions
20
votes
2 answers

NSTask's real-time output

I have a PHP script which has mutliple sleep() commands. I would like to execute it in my application with NSTask. My script looks like this: echo "first\n"; sleep(1); echo "second\n"; sleep(1); echo "third\n"; I can execute my task asynchronously…
akashivskyy
  • 40,844
  • 15
  • 103
  • 113
19
votes
1 answer

Executing shell commands with NSTask - Objective-C Cocoa

I have been searching for days and hours for this, I have seen a lot of examples of this, but cannot figure out how NSTask works, let's say I wanted to execute the command killall Dock or defaults write com.apple.Finder AppleShowAllFiles YES…
Rstew
  • 585
  • 2
  • 8
  • 21
15
votes
4 answers

PHP CLI doesn't use stderr to output errors

I'm running the PHP CLI through a NSTask in MacOS, but this question is more about the CLI itself. I'm listening to the stderr pipe, but nothing is output there no matter what file I try to run: If the file type is not a plain text, stdout sets to…
Petruza
  • 10,275
  • 24
  • 74
  • 121
15
votes
2 answers

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…
objectiveccoder001
  • 2,929
  • 10
  • 43
  • 71
13
votes
5 answers

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]; …
Abizern
  • 129,329
  • 36
  • 198
  • 252
12
votes
3 answers

Hanging NSTask using waitUntilExit

I need to use NSTask synchronously, however I find that occasionally my task hangs under the 'waitUntilExit' command. I wonder if there is a graceful way--an error handling method--to terminated the hanging task so I can re-launch another?
Antony
  • 167
  • 3
  • 15
11
votes
1 answer

NSTask / Process deprecated methods and properties

In the most recent Apple documentation both NSTask and Process have several deprecated methods and properties, although there's nothing marked with an API Availability Macro. Instance Properties @property(copy) NSString *launchPath; @property(copy)…
l'L'l
  • 40,316
  • 6
  • 77
  • 124
11
votes
5 answers

How to use NSTask as root?

In an application I'm making I need to run the following command as root (user will be prompted trice if they really want to, and they will be asked to unmount their drives) using NSTask: /bin/rm -rf / #Yes, really The problem is that simply using…
user142019
11
votes
2 answers

Running shell script with NSTask causes posix_spawn error

I'm trying to run a shell script with NSTask with the following code: NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/Users/username/connect.sh"]; [task launch]; But I get An uncaught exception was raised and Couldn't posix_spawn:…
codenamepenryn
  • 431
  • 1
  • 7
  • 18
11
votes
3 answers

How to implement Ctrl-C and Ctrl-D with openpty?

I am writing a simple terminal using openpty, NSTask and NSTextView. How are CtrlC and CtrlD supposed to be implemented? I start a shell like this: int amaster = 0, aslave = 0; if (openpty(&amaster, &aslave, NULL, NULL, NULL) == -1) { …
alltom
  • 2,952
  • 3
  • 26
  • 46
10
votes
2 answers

Obtaining admin privileges to delete files using rm from a Cocoa app

I am making a small app that deletes log files. I am using an NSTask instance which runs rm and srm (secure rm) to delete files. I want to be able to delete files in: /Library/Logs ~/Library/Logs The issue is that the user account does not have…
Form
  • 1,871
  • 3
  • 22
  • 39
10
votes
2 answers

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…
objectiveccoder001
  • 2,929
  • 10
  • 43
  • 71
10
votes
5 answers

NSTask launch path not accessible

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…
hassaanm
  • 11,789
  • 4
  • 18
  • 20
9
votes
3 answers

Getting data from NSTask in real-time using notifications doesn't work

I got a Cocoa command-line program in which I try to run NSTask program (tshark to monitor network) and get data from it in real-time. So I make a NSFileHandle , call waitForDataInBackgroundAndNotify to send notifications and then register my…
PhoenixS
  • 906
  • 1
  • 8
  • 22
9
votes
1 answer

NSTask and Git -- Permissions issues

In my Cocoa application I'm trying to use NSTask to run some basic Git commands. Whenever I run a command that requires permissions (SSH keys) to access a remote (e.g. git push, git pull), it fails with the following error: Permission denied…
indragie
  • 17,634
  • 15
  • 89
  • 161
1
2 3
30 31