Code Block // pass arguments Not Working let url = NSURL(fileURLWithPath: "/Volumes/DATA/Dev/cppPlayground/cmake-build-debug/cppPlayground" , isDirectory: false) as URL let configuration = NSWorkspace.OpenConfiguration() var aStr = [String]() aStr.append("1st") aStr.append("2nd") configuration.arguments = aStr NSWorkspace.shared.openApplication(at: url, configuration: configuration, completionHandler: nil)
https://developer.apple.com/documentation/appkit/nsworkspace/3172700-openapplication
I try to open another cpp app that has main method ' int main(int argc, char **argv) '
and pass arguments.
but it was failed.
app was open successful but arguments was empty.
Code Block // Working But deprecated. let task = Process() task.arguments = ["test test", "2nd Argument", "3rd"] task.launchPath = "/Volumes/DATA/Dev/cppPlayground/cmake-build-debug/cppPlayground" task.launch()
this code was work. but available macOS 10.0–10.13.
is there something wrong?
I do not know much about NSWorkspace.
But there are some replacements for the deprecated methods:
But there are some replacements for the deprecated methods:
Code Block let task = Process() task.arguments = ["test test", "2nd Argument", "3rd"] task.executableURL = URL(fileURLWithPath: "/Volumes/DATA/Dev/cppPlayground/cmake-build-debug/cppPlayground") do { try task.run() } catch { print(error) }