판독 중지 시 파이프 파손 오류

판독 중지 시 파이프 파손 오류

두 FLAC 파일의 오디오 콘텐츠를 임시 파일로 디코딩하지 않고 비교하기 위한 빠르고 더러운 bash 기능을 만들려고 합니다. 명령줄 도구를 사용하여 flac각 파일을 명명된 파이프로 디코딩한 후 다음으로 연결했습니다 cmp.

function flacdiff {
        local pipe1="/tmp/$(randomString)"
        mkfifo "$pipe1" 
        flac --silent --decode --force-raw-format --sign=signed --endian=little "$1" --stdout > "$pipe1" &

        local pipe2="/tmp/$(randomString)"
        mkfifo "$pipe2"
        flac --silent --decode --force-raw-format --sign=signed --endian=little "$2" --stdout > "$pipe2" &

        cmp -b "$pipe1" "$pipe2"
        local result=$?

        rm "$pipe1"
        rm "$pipe2"

        return $result
}

파일이 동일하면 스크립트가 제대로 작동합니다. 그러나 서로 다를 경우 파이프 파손 오류가 발생합니다.

[1]-  Broken pipe: 13         flac --silent --decode --force-raw-format --sign=signed --endian=little "$1" --stdout > "$pipe1"
[2]+  Broken pipe: 13         flac --silent --decode --force-raw-format --sign=signed --endian=little "$2" --stdout > "$pipe2"

cmp파이프의 쓰기 끝이 여전히 활성 상태인 동안 첫 번째 불일치가 발생하자마자 읽기가 중지되기 때문이라고 생각합니다 . 제 질문은 이 가정이 맞는지, 깨진 파이프 오류를 방지하고 스크립트를 수정할 수 있는지입니다.

답변1

사용:

cmp -s \
    <(flac --silent --decode --force-raw-format --sign=signed --endian=little "$1" --stdout) \
    <(flac --silent --decode --force-raw-format --sign=signed --endian=little "$2" --stdout)

관련 정보