Unexpected error using "stdin" in bedtools intersect as a piped command
With v2.27.1 (or any version I ever used) instead of stdin use -
(...) | bedtools intersect -a - -b blacklist.bed -v &gt; out.bam

Be aware that the output of this is a BAM, not SAM file. It would be easier though to simply make a list of regions you want to keep, e.g. the complement of the backlist file with the entire genome (bedtools complement), and then use samtools view -L option to only keep overlapping reads. That saves you the run through bedtools.