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) cmd := exec.Command(audioCmd, *soundFilePtr)
var stdoutBuf, stderrBuf bytes.Buffer var stdoutBuf, stderrBuf bytes.Buffer
stdoutIn, _ := cmd.StdoutPipe() stdoutIn, err := cmd.StdoutPipe()
stderrIn, _ := cmd.StderrPipe() 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 var errStdout, errStderr error
stdout := io.MultiWriter(os.Stdout, &stdoutBuf) stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
stderr := io.MultiWriter(os.Stderr, &stderrBuf) stderr := io.MultiWriter(os.Stderr, &stderrBuf)
err := cmd.Start() err = cmd.Start()
if err != nil { if err != nil {
log.Log(logger.Fatal, "cmd.Start() for 'play' failed", "error", err.Error()) 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) log.Log(logger.Debug, "'alsactl' executable path", "path", path)
for {
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore") cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
err := cmdInit.Run() for cmdInit.Run() != nil {
if err == nil {
break
}
log.Log(logger.Warning, "cmd.Run() for 'alsactl' failed", "error", err.Error()) log.Log(logger.Warning, "cmd.Run() for 'alsactl' failed", "error", err.Error())
time.Sleep(sleepDur) time.Sleep(sleepDur)
} }