pe.cmd = exec.Command(pe.Cmd, pyTmpFle.Name()) //nolint:gosec
if pe.Envs != nil {
pe.cmd.Env = pe.Envs
}
stdout, err := pe.cmd.StdoutPipe()
if err != nil {
l.Errorf("cmd.StdoutPipe failed: %s", err.Error())
return err
}
pe.cmd.Stderr = pe.cmd.Stdout
l.Debugf("starting cmd %s, envs: %+#v", pe.cmd.String(), pe.cmd.Env)
if err := pe.cmd.Start(); err != nil {
l.Errorf("start pythond input %s failed: %s", pe.Name, err.Error())
return err
}
go func() {
tick := time.NewTicker(time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
tmp := make([]byte, 1024)
_, err := stdout.Read(tmp)
l.Debug(string(tmp))
if err != nil {
l.Debugf("stdout.Read failed: %v", err)
return
}
case <-x.Exit.Wait():
return
case <-pe.semStop.Wait():
return
}
}
}()
return nil
1.2. 扩展
https://pkg.go.dev/os/exec#pkg-variables
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)