1 Star 0 Fork 0

kzangv / gsf-fof

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
shell_unix.go 637 Bytes
一键复制 编辑 原始数据 按行查看 历史
kzangv 提交于 2023-03-21 13:53 . fixed
//go:build !windows
package shell
import (
"errors"
"os/exec"
"syscall"
)
type UnixShell struct {
*exec.Cmd
}
func (c *UnixShell) New(command string) {
c.Cmd = exec.Command("/bin/bash", "-c", command)
c.Cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
}
func (c UnixShell) Exec() (string, error) {
output, err := c.Cmd.CombinedOutput()
if err != nil {
return "", err
}
return string(output), nil
}
func (c UnixShell) Destroy() error {
if c.Cmd.Process.Pid > 0 {
return syscall.Kill(-c.Cmd.Process.Pid, syscall.SIGKILL)
}
return errors.New("timeout killed")
}
func newCmd() Cmd {
return &UnixShell{}
}
Go
1
https://gitee.com/kzangv/gsf-fof.git
git@gitee.com:kzangv/gsf-fof.git
kzangv
gsf-fof
gsf-fof
v0.4.2

搜索帮助