You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
449 B
Go
29 lines
449 B
Go
//go:build windows
|
|
|
|
package common
|
|
|
|
import (
|
|
"bytes"
|
|
"os/exec"
|
|
)
|
|
|
|
// ShellExec exec command by shell
|
|
// cmdLine e.g. "ls -al"
|
|
func ShellExec(cmdLine string, shells ...string) (string, error) {
|
|
// shell := "/bin/sh"
|
|
shell := "cmd"
|
|
if len(shells) > 0 {
|
|
shell = shells[0]
|
|
}
|
|
|
|
var out bytes.Buffer
|
|
|
|
cmd := exec.Command(shell, "/c", cmdLine)
|
|
cmd.Stdout = &out
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return "", err
|
|
}
|
|
return out.String(), nil
|
|
}
|