我需要能够从Swift中运行.sh文件!我查看了相关资料,但是人们要求我在Swift文件中运行shell程序,但是这并没有起作用。我只是想运行一个命令。这个shell命令确实需要参数,这些参数将从应用程序中传递进来。我尝试运行的命令是:
chmod a-x /Applications/the input here
我还必须能够接受用户输入密码。那么如何输入密码呢?
编辑
我已经尝试了:
import Foundation
let task = NSTask();
task.launchPath = "/bin/chmod"
task.arguments = ["a-x /Applications/application.app"]
task.launch()
有没有人有什么技巧?
FileManager.default.setAttributes([FileAttributeKey.posixPermissions: 0o000], ofItemAtPath: "/your/file")
(将适当的数字替换为000
)? - Raphael