21 lines
484 B
Swift
21 lines
484 B
Swift
|
import Foundation
|
||
|
|
||
|
@discardableResult
|
||
|
func safeShell(_ command: String) throws -> String {
|
||
|
let task = Process()
|
||
|
let pipe = Pipe()
|
||
|
|
||
|
task.standardOutput = pipe
|
||
|
task.standardError = pipe
|
||
|
task.arguments = ["-cl", 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
|
||
|
}
|