How to execute a shell command with root permission from swift

旧城冷巷雨未停 提交于 2020-01-22 15:27:17

问题


I am new on Swift and I am trying to create a very simple application that executes a root shell command when you press a round button.

I have found the following link online, that explains how to execute a shell command with user permission on swift, but it doesn't tell how to do it with root privileges: http://practicalswift.com/2014/06/25/how-to-execute-shell-commands-from-swift/

How can I do it?


回答1:


Quick-and-dirty:

NSAppleScript(source: "do shell script \"sudo whatever\" with administrator " +
    "privileges")!.executeAndReturnError(nil)

Alternatively look into privileged helper tools but expect that to be much more complicated.



来源:https://stackoverflow.com/questions/26707557/how-to-execute-a-shell-command-with-root-permission-from-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!