Documentation ¶
Index ¶
- Variables
- func CheckBadCmd(s string) bool
- func RunCmd(cmdArgs []string, timeout ...time.Duration) cmd.Status
- func RunCmdCombinedOutput(cmdArgs []string, timeout ...time.Duration) cmd.Status
- func RunCmdWithContext(ctx context.Context, cmdArgs []string) cmd.Status
- func RunCmdWithOptions(cmdArgs []string, opts cmd.Options, timeout ...time.Duration) cmd.Status
- func RunShell(sh string, args ...string) (ok bool)
- func RunShellTimeout(sh string, timeout time.Duration, args ...string) (ok bool)
- func RunShellTimeoutWithResult(sh string, timeout time.Duration, args ...string) (stdout, errout string, ok bool)
- func RunShellWithResult(sh string, args ...string) (stdout, errout string, ok bool)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultCMDTimeout 命令执行超时时间默认值 DefaultCMDTimeout = 3 * time.Second ErrCMDTimeout = errors.New("command execution timed out") )
View Source
var ( // DefaultShellTimeout Shell 执行默认超时时间 DefaultShellTimeout = 10 * time.Second // BashCmd 主命令绝对路径 BashCmd = []string{"/bin/bash"} )
Functions ¶
func RunCmdCombinedOutput ¶ added in v0.5.3
RunCmdCombinedOutput 运行命令, 合并输出和错误 2>&1
func RunCmdWithContext ¶
RunCmdWithContext 运行命令, 返回结果和状态
func RunCmdWithOptions ¶ added in v0.5.3
func RunShellTimeout ¶ added in v0.6.6
RunShellTimeout 运行 Shell 脚本返回是否执行成功
func RunShellTimeoutWithResult ¶ added in v0.6.6
func RunShellTimeoutWithResult(sh string, timeout time.Duration, args ...string) (stdout, errout string, ok bool)
RunShellTimeoutWithResult 运行 Shell 脚本并返回标准输出和错误输出, 以及是否执行成功 示例命令: /bin/bash /opt/app/script/echo.sh my-app 示例调用: RunShellTimeoutWithResult("/opt/app/script/echo.sh", 3*time.Second, "my-app")
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.