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.
::: tip NOTE In order to ensure security, unless you must use it, try not to use this interface in other cases. :::
::: tip API
sudo.has()
:::
No parameters
| Type | Description |
|---|---|
| boolean | Returns true if sudo is supported, false otherwise |
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")
end
::: tip API
sudo.run(cmd: <string>)
:::
| Parameter | Description |
|---|---|
| cmd | Required. Shell command to execute |
| Type | Description |
|---|---|
| boolean | Returns true on success, false on failure |
For specific usage, please refer to: os.run.
import("privilege.sudo")
sudo.run("rm /system/file")
::: tip API
sudo.runv(argv: <table>)
:::
| Parameter | Description |
|---|---|
| argv | Required. Command argument list |
| Type | Description |
|---|---|
| boolean | Returns true on success, false on failure |
For specific usage, please refer to: os.runv.
::: tip API
sudo.exec(cmd: <string>)
:::
| Parameter | Description |
|---|---|
| cmd | Required. Shell command to execute |
| Type | Description |
|---|---|
| boolean | Returns true on success, false on failure |
For specific usage, please refer to: os.exec.
::: tip API
sudo.execv(argv: <table>)
:::
| Parameter | Description |
|---|---|
| argv | Required. Command argument list |
| Type | Description |
|---|---|
| boolean | Returns true on success, false on failure |
For specific usage, please refer to: os.execv.
::: tip API
sudo.iorun(cmd: <string>)
:::
| Parameter | Description |
|---|---|
| cmd | Required. Shell command to execute |
| Type | Description |
|---|---|
| string | Returns output content on success, nil on failure |
For specific usage, please refer to: os.iorun.
::: tip API
sudo.iorunv(argv: <table>)
:::
| Parameter | Description |
|---|---|
| argv | Required. Command argument list |
| Type | Description |
|---|---|
| string | Returns output content on success, nil on failure |
For specific usage, please refer to: os.iorunv.