💨

Shell 命令

举个例子

package main import ( "github.com/sohaha/zlsgo/zlog" "github.com/sohaha/zlsgo/zshell" ) func main() { code, outStr, errStr, err := zshell.Run("ls -a") if err != nil { zlog.Fatal(err) } zlog.Infof("状态码:%d\n执行结果:%s\n错误结果:%s",code, outStr, errStr) }

说明

// 执行并且获取结果 zshell.Run(command string) zshell.RunContext(ctx context.Context, command string) // 执行但是不获取结果 zshell.BgRun(command string) // 自定义 Std 输出 zshell.OutRun() // 管道使用 // 如需要执行这个命令: ls -a | grep go code, outStr, errStr, err := zshell.PipeExecCommand( context.Background(), [][]string{ {"ls","-a"}, {"grep", "go"} })