[英]How to execute a shell command with root permission from swift
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. 我是Swift的新手,我试图创建一个非常简单的应用程序,当您按下圆形按钮时,该应用程序会执行root shell命令。
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/ 我在网上找到了以下链接,该链接说明了如何在swift上具有用户权限的情况下执行shell命令,但并未说明如何使用root特权进行操作: http : //practicalswift.com/2014/06/25/如何从swift /执行壳命令
How can I do it? 我该怎么做?
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. 另外,也可以研究特权帮助器工具,但希望它要复杂得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.