mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-12 02:29:42 +08:00
feat: exec command hook , close #79
This commit is contained in:
23
core/hookutil.go
Normal file
23
core/hookutil.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func ExecCommandString(ctx context.Context, cmd string) error {
|
||||
if cmd == "" {
|
||||
return nil
|
||||
}
|
||||
var execCmd *exec.Cmd
|
||||
if runtime.GOOS == "windows" {
|
||||
execCmd = exec.CommandContext(ctx, "cmd.exe", "/C", cmd)
|
||||
} else {
|
||||
execCmd = exec.CommandContext(ctx, "sh", "-c", cmd)
|
||||
}
|
||||
execCmd.Stdout = os.Stdout
|
||||
execCmd.Stderr = os.Stderr
|
||||
return execCmd.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user