audio-player: error checking

This commit is contained in:
Ella Pietraroia 2020-03-02 12:33:01 +10:30
parent c5fb58e70c
commit 4690209fd5
2 changed files with 11 additions and 9 deletions

View File

@ -76,14 +76,20 @@ func main() {
cmd := exec.Command(audioCmd, *soundFilePtr)
var stdoutBuf, stderrBuf bytes.Buffer
stdoutIn, _ := cmd.StdoutPipe()
stderrIn, _ := cmd.StderrPipe()
stdoutIn, err := cmd.StdoutPipe()
if err != nil {
log.Log(logger.Error, "failed to make stdout pipe", "error", err.Error())
}
stderrIn, err := cmd.StderrPipe()
if err != nil {
log.Log(logger.Error, "failed to make stderr pipe", "error", err.Error())
}
var errStdout, errStderr error
stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
stderr := io.MultiWriter(os.Stderr, &stderrBuf)
err := cmd.Start()
err = cmd.Start()
if err != nil {
log.Log(logger.Fatal, "cmd.Start() for 'play' failed", "error", err.Error())
}

View File

@ -22,12 +22,8 @@ func initCommand(log *logger.Logger) {
}
log.Log(logger.Debug, "'alsactl' executable path", "path", path)
for {
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
err := cmdInit.Run()
if err == nil {
break
}
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
for cmdInit.Run() != nil {
log.Log(logger.Warning, "cmd.Run() for 'alsactl' failed", "error", err.Error())
time.Sleep(sleepDur)
}