nstask

NSTask's real-time output

烈酒焚心 提交于 2019-11-30 01:48:50
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 using notifications: - (void)awakeFromNib { NSTask *task = [[NSTask alloc] init]; [task setLaunchPath: @"/usr/bin/php"]; NSArray *arguments; arguments = [NSArray arrayWithObjects: @"-r", @"echo \"first\n\"; sleep(1); echo \"second\n\"; sleep(1); echo \"third\n\";", nil]; [task setArguments: arguments]; NSPipe *p = [NSPipe pipe]; [task

How to run NSTask with multiple commands

◇◆丶佛笑我妖孽 提交于 2019-11-29 15:26:49
问题 I'm trying to make a NSTask running a command like this: ps -clx | grep 'Finder' | awk '{print $2}' Here is my method - (void) processByName:(NSString*)name { NSTask *task1 = [[NSTask alloc] init]; NSPipe *pipe1 = [NSPipe pipe]; [task1 waitUntilExit]; [task1 setLaunchPath: @"/bin/ps"]; [task1 setArguments: [NSArray arrayWithObjects: @"-clx", nil]]; [task1 setStandardOutput: pipe1]; NSTask *task2 = [[NSTask alloc] init]; NSPipe *pipe2 = [NSPipe pipe]; [task2 setLaunchPath: @"/usr/bin/grep"];

NSTask's real-time output

匆匆过客 提交于 2019-11-28 22:37:42
问题 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 using notifications: - (void)awakeFromNib { NSTask *task = [[NSTask alloc] init]; [task setLaunchPath: @"/usr/bin/php"]; NSArray *arguments; arguments = [NSArray arrayWithObjects: @"-r", @"echo \"first\n\"; sleep(1); echo \"second\n\"; sleep(1);

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

强颜欢笑 提交于 2019-11-28 19:50:42
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 permissions to access some files in the system library folder, such as the Adobe logs subfolder and others. For example, only the "system" user (group?) has r/w permissions for the Adobe logs folder and its contents, and the current user doesn't even have an entry in the permissions shown in the Get Info window for the folder. What I want to be able to

cURL through NSTask not terminating if a pipe is present

孤者浪人 提交于 2019-11-28 11:31:58
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 = NSTask() let pipe = NSPipe() task.launchPath = "/usr/bin/curl" task.arguments = ["http://trove.nla

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

孤街醉人 提交于 2019-11-27 19:33:21
This question already has an answer here: How to use NSTask as root? 5 answers 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 tally Look here: http://www.sveinbjorn.org/STPrivilegedTask http://www.sheepsystems.com/sourceCode/authTasksCocoa.html HTH :-) Carlos P If you're looking for a more lightweight solution, I wrote this generic implementation which should achieve what you want: - (BOOL) runProcessAsAdministrator:(NSString*)scriptPath withArguments:(NSArray *)arguments output:(NSString **)output

How can you start a LaunchAgent for the first time without rebooting, when your code runs as a LaunchDaemon?

牧云@^-^@ 提交于 2019-11-27 17:01:35
问题 I have a LaunchDaemon. When it runs, it checks if SIMBL is installed. If SIMBL is not installed, it uses NSTask to run /usr/sbin/installer on the SIMBL.pkg. SIMBL's postflight script then tries to run a launchctl load command to start SIMBL's LaunchAgent immediately: sudo -u "$USER" -- /bin/launchctl load -F -S Aqua -D user "${LAUNCHD_PLIST}" This fails, because my LaunchDaemon's NSTask environment doesn't have $USER set. If I have my daemon detect the current user with the System

NSTask NSPipe - objective c command line help

守給你的承諾、 提交于 2019-11-27 12:55:24
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'm trying to replicate this: cd /applications/jarvis/brain/ ./server.sh but using NSTask in objective-c

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

末鹿安然 提交于 2019-11-27 12:30:51
问题 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 permissions to access some files in the system library folder, such as the Adobe logs subfolder and others. For example, only the "system" user (group?) has r/w permissions for the Adobe logs folder and its contents, and the current user doesn't even

NSTask or equivalent for iPhone [closed]

眉间皱痕 提交于 2019-11-27 09:32:14
I've an open source project (gdal) that I want to compile and run as part of an iOS app. I had been expecting to use NSTask but I see now that it was removed in iOS 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 commandline tools within their iOS applications? It wasn't removed in 3.0, it was never there. There is no way to run separate processes on the iPhone. GDAL appears to be under an MIT style license and has a library interface, so directly linking it into an iPhone