From 8625fbd8d36e104c6377459e16f5d698f600139c Mon Sep 17 00:00:00 2001 From: dudaodong Date: Mon, 2 Sep 2024 11:22:11 +0800 Subject: [PATCH] doc: update doc for ExecCommand function --- docs/api/packages/system.md | 7 +++++-- docs/en/api/packages/system.md | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/api/packages/system.md b/docs/api/packages/system.md index 3d5d360..e9b673b 100644 --- a/docs/api/packages/system.md +++ b/docs/api/packages/system.md @@ -241,7 +241,8 @@ func main() { ### ExecCommand -

执行shell命令,返回命令的stdout和stderr字符串,如果出现错误,则返回错误。参数`command`是一个完整的命令字符串,如ls-a(linux),dir(windows),ping 127.0.0.1。在linux中,使用/bin/bash-c执行命令,在windows中,使用powershell.exe执行命令。

+

执行shell命令,返回命令的stdout和stderr字符串,如果出现错误,则返回错误。参数`command`是一个完整的命令字符串,如ls-a(linux),dir(windows),ping 127.0.0.1。在linux中,使用/bin/bash-c执行命令,在windows中,使用powershell.exe执行命令。 +函数的第二个参数是cmd选项控制参数,类型是func(*exec.Cmd),可以通过这个参数设置cmd属性。

函数签名: @@ -262,7 +263,9 @@ import ( func main() { // linux or mac - stdout, stderr, err := system.ExecCommand("ls") + stdout, stderr, err := system.ExecCommand("ls", func(cmd *exec.Cmd) { + cmd.Dir = "/tmp" + }) fmt.Println("std out: ", stdout) fmt.Println("std err: ", stderr) assert.Equal("", stderr) diff --git a/docs/en/api/packages/system.md b/docs/en/api/packages/system.md index 5f0747e..1fd130e 100644 --- a/docs/en/api/packages/system.md +++ b/docs/en/api/packages/system.md @@ -242,7 +242,8 @@ func main() { ### ExecCommand -

Execute shell command, return the stdout and stderr string of command, and error if error occur. param `command` is a complete command string, like, ls -a (linux), dir(windows), ping 127.0.0.1. In linux, use /bin/bash -c to execute command, In windows, use powershell.exe to execute command.

+

Execute shell command, return the stdout and stderr string of command, and error if error occur. param `command` is a complete command string, like, ls -a (linux), dir(windows), ping 127.0.0.1. In linux, use /bin/bash -c to execute command, In windows, use powershell.exe to execute command. +The second parameter of the function is the cmd option control parameter. The type is func(*exec.Cmd). You can set the cmd attribute through this parameter.

Signature: @@ -263,7 +264,9 @@ import ( func main() { // linux or mac - stdout, stderr, err := system.ExecCommand("ls") + stdout, stderr, err := system.ExecCommand("ls", func(cmd *exec.Cmd) { + cmd.Dir = "/tmp" + }) fmt.Println("std out: ", stdout) fmt.Println("std err: ", stderr) assert.Equal("", stderr)