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
sudo.has()Parameter Description
No parameters
Return Value
| Type | Description |
|---|---|
| boolean | Returns 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.
import("privilege.sudo")
if sudo.has() then
sudo.run("rm /system/file")
endsudo.run
- Quietly running native shell commands
Function Prototype
API
sudo.run(cmd: <string>)Parameter Description
| Parameter | Description |
|---|---|
| cmd | Required. Shell command to execute |
Return Value
| Type | Description |
|---|---|
| boolean | Returns true on success, false on failure |
Usage
For specific usage, please refer to: os.run.
import("privilege.sudo")
sudo.run("rm /system/file")sudo.runv
- Quietly running native shell commands with parameter list
Function Prototype
API
sudo.runv(argv: <table>)Parameter Description
| Parameter | Description |
|---|---|
| argv | Required. Command argument list |
Return Value
| Type | Description |
|---|---|
| boolean | Returns 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
sudo.exec(cmd: <string>)Parameter Description
| Parameter | Description |
|---|---|
| cmd | Required. Shell command to execute |
Return Value
| Type | Description |
|---|---|
| boolean | Returns 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
sudo.execv(argv: <table>)Parameter Description
| Parameter | Description |
|---|---|
| argv | Required. Command argument list |
Return Value
| Type | Description |
|---|---|
| boolean | Returns 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
sudo.iorun(cmd: <string>)Parameter Description
| Parameter | Description |
|---|---|
| cmd | Required. Shell command to execute |
Return Value
| Type | Description |
|---|---|
| string | Returns 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
sudo.iorunv(argv: <table>)Parameter Description
| Parameter | Description |
|---|---|
| argv | Required. Command argument list |
Return Value
| Type | Description |
|---|---|
| string | Returns output content on success, nil on failure |
Usage
For specific usage, please refer to: os.iorunv.