nstask

Hanging NSTask using waitUntilExit

依然范特西╮ 提交于 2021-02-07 05:34:18
问题 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? 回答1: Note that if the task being run via NSTask fills the output pipe then the process will hang, effectively blocking waitUntilExit from returning. You can prevent this situation by calling [task.standardOutput.fileHandleForReading readDataToEndOfFile];

Accessing Bundle of main application while running XCTests

南笙酒味 提交于 2021-01-28 11:11:59
问题 In tests target -> General -> Testing: set Host Application to None , so that no app gets launched. But in that case I cannot use Bundle.main.resourcePath and access resources of my main application (in which some command files are included as resources and I need to run them using Process() ). Could anyone suggest a solution? 回答1: Bundle(identifier: "com.something.app") will get you the bundle for a specific bundle ID. The problem is that if your bundle ID changes for your main target this

How to wait NSTask to finish in async block

ぐ巨炮叔叔 提交于 2021-01-27 11:57:02
问题 NSURLSessionDataTask *dataTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { NSLog(@"Did fail with error %@" , [error localizedDescription]); fail(); return ; } else { } I use dataTaskWithRequest to send async http request and in the completion block, i want to run a python script . NSTask * task = [[NSTask alloc] init]; [task setLaunchPath:kPythonPath]; [task setArguments:@[self.scriptFileFullPath

How to wait NSTask to finish in async block

社会主义新天地 提交于 2021-01-27 11:54:24
问题 NSURLSessionDataTask *dataTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { NSLog(@"Did fail with error %@" , [error localizedDescription]); fail(); return ; } else { } I use dataTaskWithRequest to send async http request and in the completion block, i want to run a python script . NSTask * task = [[NSTask alloc] init]; [task setLaunchPath:kPythonPath]; [task setArguments:@[self.scriptFileFullPath

How to execute a shell command with root permission from swift

旧城冷巷雨未停 提交于 2020-01-22 15:27:17
问题 I am new on Swift and I am trying to create a very simple application that executes a root shell command when you press a round button. I have found the following link online, that explains how to execute a shell command with user permission on swift, but it doesn't tell how to do it with root privileges: http://practicalswift.com/2014/06/25/how-to-execute-shell-commands-from-swift/ How can I do it? 回答1: Quick-and-dirty: NSAppleScript(source: "do shell script \"sudo whatever\" with

NSTask launch path not accessible

微笑、不失礼 提交于 2020-01-19 15:50:07
问题 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 accessible. Help please. NSBundle *mainBundle=[NSBundle mainBundle]; NSString *path=[mainBundle pathForResource:@"script" ofType:@"sh"]; NSTask *task = [[NSTask alloc] init]; [task setLaunchPath: path]; NSLog (path); NSPipe *pipe = [NSPipe pipe]; [task

Calling xcodebuild from Swift command line tool fails

牧云@^-^@ 提交于 2020-01-16 01:11:06
问题 I'm writing simple swift command line tool application that automates some of my iOS Dev work. Everything is working except one thing - calling xcodebuild script. My method looks like this: func runTest(deviceName: String, os: String) { killAllSimulators() let sdk = "iphonesimulator" let destination = "platform=iOS Simulator,name=" + deviceName + ",OS=" + os let arguments = ["-workspace", workspace, "-scheme", scheme, "-sdk", sdk, "-destination", destination, "test"] executor.executeCommand(

xcodebuild: cdtool cannot compile: DataModelCompile /path/to/coredatamodel.xcdatamodeld dyld: Symbol not found: _OBJC_CLASS_$_OS_object

时光毁灭记忆、已成空白 提交于 2020-01-05 04:16:05
问题 I'm building a Mac Desktop/Cocoa Application to archive my iOS project, the core implementation uses NSTask with xcodebuild command, followed by raywenderlich's this guide. The root cause is the CoreData model file compile, I used this app to build my another project which didn't contain any CoreData files and no issue there. More interesting comparison is, I tried the same xcodebuild command in my terminal and it just succeed! Then I start to diff the two xcodebuild output and found some

How to terminate all threads reading from Pipe (NSPipe) related to Process (NSTask)?

你。 提交于 2020-01-04 06:36:09
问题 I am writing a MacOS/Cocoa app that monitors a remote log file using a common recipe that launches a Process (formerly NSTask ) instance on a background thread and reads stdout of the process via a Pipe (formally a NSPipe ) as listed below: class LogTail { var process : Process? = nil func dolog() { // // Run ssh fred@foo.org /usr/bin/tail -f /var/log.system.log // on a background thread and monitor it's stdout. // let processQueue = DispatchQueue.global(qos: .background) processQueue.async {

How can I tell when a FileHandle has nothing left to be read?

此生再无相见时 提交于 2020-01-04 04:13:06
问题 I'm trying to use a Pipe's fileHandleForReading's readabilityHandler to read both the standardOutput and standardError of a Process. However, the moment the terminationHandler is called is actually before the moment my readabilityHandler is called for the first time. I'm not sure why the process does this, but it means I'm not getting all the data, because I assume process termination means all output has been flushed to the pipe. Since this isn't the case, is there a way for me to tell when