I want to launch a terminal application (like "git") in my Swift application on macOS. My code looks like this:
do {
let process: Process = Process();
process.launchPath = "git";
process.arguments = [
"..."
];
process.launch();
} catch {
print("Cannot launch git: \(error)")
}
On my box git is on PATH and launches without problems in a terminal by just running git
. How can I accomplish that in my Swift application too?
Can Process
be made to resolve the application path on its own or do I have to do that myself? And if I have to do it manually, how would I do it?
Update: The start application is a GUI application, which can run from Finder as well as being debugged from Xcode.
I can read the PATH like this:
var env = ProcessInfo.processInfo.environment
var path = env["PATH"]! as String
but that value doesn't contain the terminal's PATH values.