Skip to content

privilege.sudo

This interface is used to run commands via sudo and provides platform consistency handling, which can be used for scripts that require root privileges to run.

NOTE

In order to ensure security, unless you must use it, try not to use this interface in other cases.

sudo.has

  • Determine if sudo supports

Function Prototype

API

lua
sudo.has()

Parameter Description

No parameters

Return Value

TypeDescription
booleanReturns true if sudo is supported, false otherwise

Usage

At present, sudo is supported only under macosx/linux. The administrator privilege running on Windows is not supported yet. Therefore, it is recommended to use the interface to judge the support situation before use.

lua
import("privilege.sudo")

if sudo.has() then
    sudo.run("rm /system/file")
end

sudo.run

  • Quietly running native shell commands

Function Prototype

API

lua
sudo.run(cmd: <string>)

Parameter Description

ParameterDescription
cmdRequired. Shell command to execute

Return Value

TypeDescription
booleanReturns true on success, false on failure

Usage

For specific usage, please refer to: os.run.

lua
import("privilege.sudo")

sudo.run("rm /system/file")

sudo.runv

  • Quietly running native shell commands with parameter list

Function Prototype

API

lua
sudo.runv(argv: <table>)

Parameter Description

ParameterDescription
argvRequired. Command argument list

Return Value

TypeDescription
booleanReturns true on success, false on failure

Usage

For specific usage, please refer to: os.runv.

sudo.exec

  • Echo running native shell commands

Function Prototype

API

lua
sudo.exec(cmd: <string>)

Parameter Description

ParameterDescription
cmdRequired. Shell command to execute

Return Value

TypeDescription
booleanReturns true on success, false on failure

Usage

For specific usage, please refer to: os.exec.

sudo.execv

  • Echo running native shell commands with parameter list

Function Prototype

API

lua
sudo.execv(argv: <table>)

Parameter Description

ParameterDescription
argvRequired. Command argument list

Return Value

TypeDescription
booleanReturns true on success, false on failure

Usage

For specific usage, please refer to: os.execv.

sudo.iorun

  • Quietly running native shell commands and getting output

Function Prototype

API

lua
sudo.iorun(cmd: <string>)

Parameter Description

ParameterDescription
cmdRequired. Shell command to execute

Return Value

TypeDescription
stringReturns output content on success, nil on failure

Usage

For specific usage, please refer to: os.iorun.

sudo.iorunv

  • Run the native shell command quietly and get the output with a list of parameters

Function Prototype

API

lua
sudo.iorunv(argv: <table>)

Parameter Description

ParameterDescription
argvRequired. Command argument list

Return Value

TypeDescription
stringReturns output content on success, nil on failure

Usage

For specific usage, please refer to: os.iorunv.