1

I start bash on Cygwin and type:

dd if=/dev/zero | cat /dev/null

It finishes instantly. When I type:

dd if=/dev/zero > /dev/null

it runs as expected and I can issue

killall -USR1 dd

to see the progress. Why does the former invocation finishes instantly? Is it the same on a Linux box?

*** Explanation why I asked such stupid question and possibly not so stupid question

I was compressing hdd images and some were compressed incorrectly. I ended up with the following script showing the problem:

while sleep 1 ; do killall -v -USR1 dd ; done &
dd if=/dev/zero bs=5000000 count=200 | gzip -c | gzip -cd |  wc -c

Wc should write 1000000000 at the end. The problem is that it does not on my machine:

bash-3.2$ dd if=/dev/zero bs=5000000 count=200 | gzip -c | gzip -cd |  wc -c
13+0 records in
12+0 records out
60000000 bytes (60 MB) copied, 0.834 s, 71.9 MB/s
27+0 records in
26+0 records out
130000000 bytes (130 MB) copied, 1.822 s, 71.4 MB/s
200+0 records in
200+0 records out
1000000000 bytes (1.0 GB) copied, 13.231 s, 75.6 MB/s
1005856128

Is it a bug or am I doing something wrong once again?

agsamek
  • 321
  • 1
  • 3
  • 12

4 Answers4

4

AFAIK, you first command is not functionnal. You are trying to pipe the output of /dev/zero into a command that takes no input.

cat /dev/null is just a command that outputs nothing. Piping anything something in it will therefore do nothing at all.

When you use the stdout redirect, the output of /dev/zero gets written to the file in question (/dev/null therefore nowhere).

Antoine Benkemoun
  • 7,314
  • 3
  • 42
  • 60
3

I can't think of any reason to do what you are trying to do but the following way is the one you are looking for i guess.

 dd if=/dev/zero | cat > /dev/null
Antoine Benkemoun
  • 7,314
  • 3
  • 42
  • 60
Istvan
  • 2,582
  • 3
  • 22
  • 29
2

What dd if=/dev/zero | cat /dev/null does is:

run cat /dev/null attach it's stdin to dd stdout. Problem is, that /dev/null is empty. So cat does what is asked to do: open empty file write it contents to stdout and finish.

cat does pipe output from stdin only when there are no files specified. cat /dev/null - will pipe contents of /dev/null and stdin to stdout.

As such dd if=/dev/zero | cat /dev/null apart from wasting a process differs in nothing from cat /dev/null.

Hubert Kario
  • 6,361
  • 6
  • 36
  • 65
1

I tried it on Cygwin and Ubuntu and got the correct result in Ubuntu. If I don't send a signal to dd it works on Cygwin. I'm going to say that's a bug.

When I did a tee to send the output to a file, it consisted of all zero bytes, but there were too many of them.

dd if=/dev/zero bs=5000000 count=200 | gzip -c | gzip -cd |  tee dd.out | wc -c
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151