Questions tagged [nstask]

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

459 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
  • 44,342
  • 16
  • 106
  • 116
18
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
  • 11,744
  • 25
  • 84
  • 136
18
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
  • 9
  • 21
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,981
  • 10
  • 48
  • 72
13
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
  • 44,951
  • 10
  • 95
  • 146
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
  • 146,289
  • 39
  • 203
  • 257
13
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
  • 187
  • 4
  • 15
13
votes
4 answers

Real time NSTask output to NSTextView with Swift

I'm using an NSTask to run rsync, and I'd like the status to show up in the text view of a scroll view inside a window. Right now I have this: let pipe = NSPipe() task2.standardOutput = pipe task2.launch() let data =…
The Beanstalk
  • 798
  • 1
  • 5
  • 20
12
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
  • 451
  • 1
  • 7
  • 18
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

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,949
  • 3
  • 25
  • 40
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
  • 3,162
  • 4
  • 31
  • 47
10
votes
2 answers

Xcode 8 extension executing NSTask

My goal is to create an extension that executes clang-format. My code looks something like this: - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation completionHandler:(void (^)(NSError * _Nullable…
Guy Kogus
  • 7,251
  • 1
  • 27
  • 32
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,981
  • 10
  • 48
  • 72
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
  • 14,539
  • 4
  • 21
  • 20
1
2 3
30 31