Why does "tar -czh" produce a corrupt archive but "tar -ch | gzip" work fine? I am trying to backup a directory from a phone over adb.
When using the following command I get an archive which is corrupt:
adb exec-out &quot;tar -czh /sdcard/DCIM&quot; &gt; backup.tar.gz


But with the following command the archive is correct:
adb exec-out &quot;tar -ch /sdcard/DCIM | gzip&quot; &gt; backup.tar.gz

The two tar files are 48.8mB with a difference of about 200kB. The corrupt archive is smaller.
I am using adb at the Windows command line. It is necessary to receive the output as compressed data to avoid newline conversions. Both commands should provide compressed data.
My question is specifically asking why these two commands which should be identical are producing a different result.
The phone is running LineageOS 14.1 and is connected to a computer running Windows 10.
exec-out mixed up stdout and stderr
in 1st example the tar stderr message &quot;removing leading '/' from member names&quot; is redirected into target file
in 2nd example only tar stdout is piped to gzip
to avoid broken archive silent stderr see linked duplicate