mirror of
https://github.com/wlynxg/NetHive.git
synced 2025-12-24 13:08:30 +08:00
25 lines
570 B
Go
25 lines
570 B
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
)
|
|
|
|
func BashCtx(ctx context.Context, cmd string) (int, []byte, error) {
|
|
comm := exec.CommandContext(ctx, "/bin/bash", "-c", cmd)
|
|
output, err := comm.Output()
|
|
if err != nil {
|
|
return comm.ProcessState.ExitCode(), nil, err
|
|
}
|
|
return comm.ProcessState.ExitCode(), output, nil
|
|
}
|
|
|
|
func Bash(cmd string) (int, []byte, error) {
|
|
comm := exec.Command("/bin/bash", "-c", cmd)
|
|
output, err := comm.Output()
|
|
if err != nil {
|
|
return comm.ProcessState.ExitCode(), nil, err
|
|
}
|
|
return comm.ProcessState.ExitCode(), output, nil
|
|
}
|