nstask

Using NSTask to launch shell script that launches Node.JS

落花浮王杯 提交于 2019-12-12 02:53:31
问题 I have a cocoa app and I want to launch a shell script that launches Node.js. I figured I would do that with NSTask NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/bin/bash/start.sh"]; [task setArguments:[NSArray arrayWithObjects:@"start.sh", nil]]; [task setStandardOutput:[NSPipe pipe]]; [task setStandardInput:[NSPipe pipe]]; [task launch]; The script is in the root of my application. I have tried many variations in the launch path and I am stuck. Any help would be greatly

why waitForDataInBackgroundAndNotify doesn't work with the real time monitor with more than 1 argument?

我的梦境 提交于 2019-12-12 01:34:55
问题 I have found the following code from one of the API, and I'm trying to use it to do a real time monitoring of vm_stat 1: BOOL terminated = NO; -(void)realTimeMonitor { NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/bin/bash"]; [task setArguments:[NSArray arrayWithObjects:@"-c", @"/usr/bin/vm_stat 1", nil]]; //works fine // [task setArguments:[NSArray arrayWithObjects:@"-c", @"/usr/bin/vm_stat 1 | /usr/bin/awk '{print $1}'", nil]]; not working NSPipe *pipe = [NSPipe pipe]; NSPipe

Cannot pass special characters to an NSTask

扶醉桌前 提交于 2019-12-11 23:55:26
问题 In Cocoa, I would like to pass a string containing special characters to an NSTask as arguments, however the task does not get the proper string. NSString *city=@"Zürich"; // This is the string with a special character [arguments addObject:[NSString stringWithFormat:@"-iptc:city=%@",city]]; NSTask *task=[NSTask new]; [task setLaunchPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"exiftool"]]; [arguments addObjectsFromArray:[NSArray arrayWithObjects:@"-L",@"

NSUserScriptTask: cancelling tasks?

拟墨画扇 提交于 2019-12-11 19:08:40
问题 Is there any way to cancel a running NSUserScriptTask? The only way that comes to mind is to launch a separate process (a command line tool) via NSTask, whose only purpose is to run the NSUserScriptTask, and then terminate the command line tool via NSTask when necessary. However, that seems a bit far-fetched and not very optimized... Any ideas? 来源: https://stackoverflow.com/questions/15599493/nsuserscripttask-cancelling-tasks

NoClassDefFoundError when running shell script

女生的网名这么多〃 提交于 2019-12-11 17:32:06
问题 Here is the error: Exception in thread "main" java.lang.NoClassDefFoundError: org/alicebot/server/net/AliceServer Caused by: java.lang.ClassNotFoundException: org.alicebot.server.net.AliceServer at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301

Can someone help me spot a leak in this NSPipe/NSFileHandle code?

我的未来我决定 提交于 2019-12-11 10:59:50
问题 So I'm having this issue where once this NSFileHandle/NSPipe gets triggered... my CPU use and memory start going crazy. Problem is I'm finding it hard to find this leak. Any advice or help is appreciated. Cheers. .h NSTask *task; NSPipe *pipe; NSFileHandle *fileHandle; @property (weak) IBOutlet NSTextField *commandInputTextField; @property (unsafe_unretained) IBOutlet NSTextView *nsTastOutput; @property (weak) IBOutlet NSButton *useOutputSwitch; .m - (id)init { [[NSNotificationCenter

NSTask only returning standardError in release build

你说的曾经没有我的故事 提交于 2019-12-11 10:34:43
问题 First of all, when debugging and running in Xcode everything works as expected. But when I try to "share" my app, i.e. make a release build, my NSTask won't output any standardOutput while standardErrors ARE put out. How is that possible? My code - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self) { // Initialization code here. } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readPipe:) name

Using Authorization Services with NSTask

半城伤御伤魂 提交于 2019-12-11 10:08:13
问题 Ok, I am using NSTask to run a shell script that needs to be run with administrator privileges. I am using some code from this question: NSTask and AuthorizationCreate. Here is what I currently have: //Authorization Create AuthorizationRef myAuthorizationRef; OSStatus myStatus; myStatus = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed , &myAuthorizationRef); AuthorizationItem myItems[1]; myItems[0].name = "com

cURL through NSTask not terminating if a pipe is present

别来无恙 提交于 2019-12-11 09:53:25
问题 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

Swift iOS: dyld: dyld_sim cannot be loaded in a restricted process

落花浮王杯 提交于 2019-12-11 07:46:36
问题 I'm making an iOS app for jailbroken devices running iOS 12 or newer. I need my app to run a command line command, so to achieve that I use a custom Objective-C header file which creates the object NSTask and everything it needs, and then, using Bridging Headers I expose it to Swift. So, to run a task I use the following function: func task(launchPath: String, arguments: String...) -> NSString { let task = NSTask.init() task?.setLaunchPath(launchPath) task?.arguments = arguments // Create a