Command line "launch path not accessible"
Solution 1
I think the problem is that you actually want to execute the shell and have it execute the mdtool, rather than directly execute mdtool
Try passing "/bin/bash" as the launchpath, and then include the path to mdtool as part of the argument string.
Solution 2
Recently I encounter a similar problem, but my solution is different.
I fix the problem by changing the permission mode of the script. Specifically, chmod 777 xxx
. The key is to give the execution permission.
Let's conduct a controlled experiment to verify it:
prepare a script with path
/tmp/a.sh
and permission666
The content of
/tmp/a.sh
:
#!/bin/sh
echo aaa
- prepare a
swift
script to launch the script:
import Foundation
let fileManager = FileManager.default
let path = fileManager.currentDirectoryPath
func shell(launchPath: String, arguments: [String] = []) -> NSString? {
let task = Process()
task.launchPath = launchPath
task.arguments = arguments
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
return output
}
if let output = shell(launchPath: "/tmp/a.sh", arguments: []) {
print(output)
}
The output is:
... *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'launch path not accessible'
- change the permission of
/tmp/a.sh
to777
(by granting the execution permission) and then re-run theswift
script:
aaa
mgChristopher
Updated on June 17, 2022Comments
-
mgChristopher about 2 years
I recently found out that I can create Swift command line scripts.
I decided to see if I could build my Xamarin project using it.
Unfortunately I am getting the following error and I don't know how to fix it.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'launch path not accessible'
Here is my script:
#!/usr/bin/env swift import Foundation print("Building Script") let fileManager = NSFileManager.defaultManager() let path = fileManager.currentDirectoryPath func shell(launchPath: String, arguments: [String] = []) -> NSString? { let task = NSTask() task.launchPath = launchPath task.arguments = arguments let pipe = NSPipe() task.standardOutput = pipe task.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() let output = NSString(data: data, encoding: NSUTF8StringEncoding) return output } if let output = shell("/Applications/Xamarin\\ Studio.app/Contents/MacOS/mdtool", arguments: ["-v build", "\"--configuration:Beta|iPhone\"", "MyApp.iOS.sln"]) { print(output) }
Any thoughts?
-
mgChristopher about 8 yearsWhen I changed the code to look like this
shell("/bin/bash", arguments: ["/Applications/Xamarin\\ Studio.app/Contents/MacOS/mdtool", "-v build", "\"--configuration:Beta|iPhone\"", "MyApp.iOS.sln"])
I now longer get the exception. Instead I get/bin/bash: /Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool: No such file or directory
-
Jason about 8 yearsinteresting - I wonder if escaping the space is necessary? Or maybe you need a single \ instead of \\? I would play with that, or try creating a symlink that doesn't have the space in it?
-
mgChristopher about 8 yearsI have it working!
shell("/bin/bash", arguments: ["-c", "'/Applications/Xamarin Studio.app/Contents/MacOS/mdtool' -v build '--configuration:Beta|iPhone' MyApp.iOS.sln"])
You help has been invaluable. What is the best way to share the answer on this?