我試圖從用Swift編寫的Mac應用程序執行「history」命令。Swift進程 - 執行命令錯誤
@discardableResult
func shell(_ args: String...) -> Int32 {
let task = Process()
task.launchPath = "/bin/bash"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
shell("history")
,它總是返回我這個錯誤:
env: history: No such file or directory
有什麼不對?真的有可能從Mac App使用用戶命令行歷史記錄?
在同一個腳本中,我如何導出日期? 「export HISTTIMEFORMAT = \'%m /%d - %H:%M:%S:\'」返回相同的'沒有這樣的文件或目錄' – Marco