Search code examples
batch-filepipestdoutstdinfc

How to use the output of 2 applications as the input of another (Windows/DOS batch files)?


In Windows/DOS batch files when you want to use the output of one application as the input for another, you use the pipe symbol:

app1.exe | app2.exe

I am trying to do something a little more complex. I want to use the output of 2 programs as the input of another. Specifically:

fc.exe [output of app1.exe] [output of app2.exe]

Obviously, I can do the following

app1.exe > tmp1.txt
app2.exe > tmp2.txt
fc.exe tmp1.txt tmp2.txt

But is there a better way to do this, preferably without creating temp files?

Note that I'm specifically using the Windows/DOS external application fc.exe (FileCompare) in what I'm doing, so if there are any special tricks for that tool, answers that are specific to it are welcome.

Related is this somewhat similar question for Linux: Redirect two or more STDOUT to a single STDIN


Solution

  • The fc command expects command line arguments that specify files containing the input data to compare.

    But fc does not read the console input (STDIN, hande 0; see Redirection), which is something completely different than that command line arguments, so you cannot use input redirection (<) or piping (|, with fc on the right side) to provide the input data.

    So you will have to use temporary files, as you anyway already did.