代码拉取完成,页面将自动刷新
package command
import (
"os"
"sync"
"time"
)
type Option struct {
Timeout *time.Duration
Stdout *os.File
Stderr *os.File
Callback func(pid int)
}
// pidMap 用于存储所有的子进程pid,以便在主程序退出时,kill掉所有的相关子进程
var pidMap sync.Map
// 当主程序退出时,从pidMap中获取所有的pid,然后kill掉
func CloseChildProccess(pid ...int) {
if len(pid) > 0 {
for _, p := range pid {
closeProcess(p)
}
return
}
pidMap.Range(func(key, value interface{}) bool {
if pid, ok := value.(int); ok {
closeProcess(pid)
}
return true
})
}
// ExecCommand 执行cmd命令操作
func ExecCommand(name string, args []string, timeout ...time.Duration) (out string, err error) {
opt := Option{}
if len(timeout) > 0 {
opt.Timeout = &timeout[0]
}
return execCommand(name, args, opt)
}
func ExecCommandV2(name string, args []string, opt Option) (out string, err error) {
return execCommand(name, args, opt)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。