nstask

How to use NSTask as root?

跟風遠走 提交于 2019-11-27 08:43:32
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 Substitute User Do ( sudo ) doesn't work as the user needs to enter the password to the non-available stdin. I'd rather like to show the user the same window as you'd see when you click the lock in Preferences.app, like this (hopefully with a shorter password): (source: quickpwn.com ) Can anyone help me with this? Thanks. Check out STPrivilegedTask ,

cURL through NSTask not terminating if a pipe is present

浪尽此生 提交于 2019-11-27 06:23:05
问题 I am trying to read the contents of a URL synchronously for a simple command-line batch script in Swift. I am using cURL for simplicity's sake - I know I could use NSURLSession if I had to. I am also building this with swift build using the open-source version of Swift on OSX. The problem is that on certain URLs, the NSTask never terminates, if stdout has been redirected to a pipe. // This will hang, and when terminated with Ctrl-C reports "(23) Failed writing body" import Foundation let task

Executing shell commands with NSTask - Objective-C Cocoa

孤人 提交于 2019-11-27 04:05:49
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 something like that, how would I go about doing this. I know how to execute an external shell script (sh) but need to be more sophisticated and use NSTask instead. Thanks for any help!! You could do something like: NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/bin/bash"]; [task setArguments:@[ @"-c", @"/usr/bin/killall Dock" ]]; [task launch

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

强颜欢笑 提交于 2019-11-26 22:18:12
问题 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 output pipe. NSPipe *outPipe = [[NSPipe alloc] init]; [task setStandardOutput:outPipe]; [task launch]; NSData *data = [[outPipe fileHandleForReading] readDataToEndOfFile]; NSString *path =

How to give permission using NSTask - objective-c [duplicate]

老子叫甜甜 提交于 2019-11-26 19:55:09
问题 This question already has answers here : How to use NSTask as root? (5 answers) Closed 2 years ago . I need to basically do a "sudo" but, I need to give that kind of permission to my NSTask code. Is this possible? Thanks, Elijah 回答1: Look here: http://www.sveinbjorn.org/STPrivilegedTask http://www.sheepsystems.com/sourceCode/authTasksCocoa.html HTH :-) 回答2: If you're looking for a more lightweight solution, I wrote this generic implementation which should achieve what you want: - (BOOL)

NSTask NSPipe - objective c command line help

瘦欲@ 提交于 2019-11-26 16:09:35
问题 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]; NSData * dataRead = [read readDataToEndOfFile]; NSString * stringRead = [[[NSString alloc] initWithData:dataRead encoding:NSUTF8StringEncoding] autorelease]; So I

Real time NSTask output to NSTextView with Swift

一曲冷凌霜 提交于 2019-11-26 15:29:59
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 = pipe.fileHandleForReading.readDataToEndOfFile() let output: String = NSString(data: data, encoding: NSASCIIStringEncoding)! as String textView.string = output And that get's me the some of the statistics about the transfer, but I'd like to get the output in real time, like what get's printed out when I run the app in Xcode, and put it into the text view. Is there a way to do this?

How to use NSTask as root?

一曲冷凌霜 提交于 2019-11-26 14:16:38
问题 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 Substitute User Do ( sudo ) doesn't work as the user needs to enter the password to the non-available stdin. I'd rather like to show the user the same window as you'd see when you click the lock in Preferences.app, like this (hopefully with a

Real time NSTask output to NSTextView with Swift

亡梦爱人 提交于 2019-11-26 03:59:02
问题 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 = pipe.fileHandleForReading.readDataToEndOfFile() let output: String = NSString(data: data, encoding: NSASCIIStringEncoding)! as String textView.string = output And that get\'s me the some of the statistics about the transfer, but I\'d like to get the output in real time, like