0

I'm trying to compare the output of my fizzbuzz.js program:

for (let i = 1; i <= 100; i++) {
  let out = "";
  if (i % 3 == 0) out += "Fizz";
  if (i % 5 == 0) out += "Buzz";
  if (i % 3 && i % 5) out = i;
  console.log(out);
}

with the contents of a expected-output.txt file which contains:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
[...]

I can't get process substitution to work:

diff -u expected-output.txt <(node fizzbuzz.js)

seems to hang indefinitely. What could be causing this?

My environment is macOS Mojave, bash 3.2.57, node v12.5.0.

EDIT: this seems to be a macOS issue. Everything works fine on a Ubuntu 18.04 machine with newer bash 4.4.19

  • 2
    @jottbe : I did give the negative note, because it was not a correct answer and not even a correct comment. – FedonKadifeli Jul 14 at 18:42
  • 2
    Can you try node fizzbuzz.js | diff -u expected-output.txt -? – FedonKadifeli Jul 14 at 18:50
  • 1
    Probably you bumped to the "seek problem" explained in unix.stackexchange.com/questions/164107/… – FedonKadifeli Jul 14 at 18:52
  • 1
    @FedonKadifeli, nah, diff shouldn't need to seek. And if it did, it would probably give a clear error about it anyway. – ilkkachu Jul 14 at 19:22
  • 2
    @jottbe, yeah, read reads from stdin, but diff expects a filename. The <(...) expands to a file name, so can be used as-is with diff. On the other hand, < <(...) redirects to stdin from that "file" – ilkkachu Jul 14 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.