I am learning some programming interview questions so I've coded FizzBuzz. I'm trying to comprare the output of my program to a known good output that's in a .txt file.

How do I check that node fizzbuzz.js output is line by line equal to a expected-output.txt file, or even diff them?

I've tried this as suggested in the duplicate question:

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

but diff outputs nothing and never seems to quit until I ^C. The program by itself runs fine, and so does diff -u expected-output.txt <(cat test.txt), it just doesn't seem to play well with node for some reason.

  • 1
    Possible duplicate of unix.stackexchange.com/q/11733/342404
    – LL3
    Commented Jul 14, 2019 at 16:47
  • 2
    Note: Unix does not have text files, they are just files. Text file were from CP/M, then MS-Dos adopted the idea, even though it did not really have a difference between text and binary files. Commented Jul 14, 2019 at 16:52
  • 1
    Possible duplicate of How to diff a file and output from the command?
    – filbranden
    Commented Jul 14, 2019 at 17:07
  • 1
    Hmm, I can't see why node.js would break with process substitution. A quick test works on my machine. Does running node fizzbuzz.js > output.txt; diff -u expected-output.txt output.txt work? If you can't get the process subst working, you might want to post another question about that (and include your version of node and a full .js script)
    – ilkkachu
    Commented Jul 14, 2019 at 17:57
  • @ilkkachu yeah, your command works fine. I'm using console.log() to print from my loop so maybe the process substitution never ends?
    – Chef Tony
    Commented Jul 14, 2019 at 18:05

1 Answer 1


In Bash/ksh/Zsh:

diff -u file.txt <(some command)

The <(some command) construct is called process substitution, and it makes the output from some command available as if from a file, so diff can read it. (It sets up pipes from the command and expands to the name of a named pipe or /dev/fd/N).

Similarly, >(some command) could be used to redirect writes to the command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .