Skip to content

Commit

Permalink
fix: 屏蔽调用外部程序终端显示;
Browse files Browse the repository at this point in the history
  • Loading branch information
speauty committed Apr 7, 2023
1 parent 9181272 commit d0dfb9a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/processor/whisper/whisper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"strings"
"sync"
"syscall"
"titmouse/lib/log"
)

Expand Down Expand Up @@ -68,6 +69,7 @@ func (customW *Whisper) LoadGraphics() error {
}

currentCMD := exec.Command(customW.cfg.CmdPath, "-la")
currentCMD.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
currentStdout, err := currentCMD.StdoutPipe()
if err != nil {
customW.log().Errorf("绑定标准输出失败, 错误: %s, 指令: %s", err, currentCMD.String())
Expand Down Expand Up @@ -132,16 +134,18 @@ func (customW *Whisper) Transform(param *TransformParams) error {
args = append(args, "-f", param.PathAudioFile)

currentCMD := exec.Command(customW.cfg.CmdPath, args...)
currentCMD.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
var stderr bytes.Buffer
var stdout bytes.Buffer
currentCMD.Stderr = &stderr
currentCMD.Stdout = &stdout

if err := currentCMD.Start(); err != nil {
customW.log().Errorf("转换失败, 错误: %s, 指令: %s", err, currentCMD.String())
return err
}

if err := currentCMD.Wait(); err != nil {
fmt.Println(err)
customW.log().Errorf("转换失败, 错误: %s(%s), 指令: %s", err, stderr.String(), currentCMD.String())
}
return nil
Expand Down

0 comments on commit d0dfb9a

Please sign in to comment.