Last active
July 18, 2024 10:20
-
-
Save erdemildiz/ed576d6aaad866a5a1d21c55b9450313 to your computer and use it in GitHub Desktop.
Run Shell Script on MacOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func callShell(_ command: String) throws -> String { | |
let task = Process() | |
let pipe = Pipe() | |
task.standardOutput = pipe | |
task.standardError = pipe | |
task.arguments = ["-c", command] | |
task.executableURL = URL(fileURLWithPath: "/bin/zsh") | |
task.standardInput = nil | |
try task.run() | |
let data = pipe.fileHandleForReading.readDataToEndOfFile() | |
let output = String(data: data, encoding: .utf8)! | |
return output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To get help
https://ss64.com/mac/