如何在Swift中以root权限执行Shell命令

如何在Swift中以root权限执行Shell命令

本文介绍了如何在Swift中以root权限执行Shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Swift的新手,我试图创建一个非常简单的应用程序,当您按下圆形按钮时,该应用程序会执行root shell命令.

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上具有用户权限的情况下执行shell命令,但并没有说明如何使用root特权进行操作:"> http://practicalswift.com/2014/06/25/how-to-execute-shell -commands-from-swift/

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/

我该怎么办?

推荐答案

快捷方式:

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.

这篇关于如何在Swift中以root权限执行Shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 03:36