1

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

  • if the output of the apps is just one line, you can capture them with a `for` loop and do a string compare. If the outputs are several lines, I'd recommend using PowerShell instead (same logic, but PS can handle multi-line variables) – Stephan Jan 01 '21 at 21:23
  • @Stephan Thanks for the ideas. It runs via WSH and the outputs of `app1.exe` and `app2.exe` are more than 1 line. Unfortunately, loading PS from WSH seems to reduce performance significantly. – RockPaperLz- Mask it or Casket Jan 01 '21 at 21:45
  • 1
    Then use wsh to do what you want. It can capture output and run programs and process files. – user14797724 Jan 01 '21 at 22:25
  • @user14797724 Thanks. I'm working on it, but running into performance issues: See https://stackoverflow.com/questions/65534737/how-to-performance-optimize-standard-output-stdout-redirection-from-an-applica – RockPaperLz- Mask it or Casket Jan 01 '21 at 23:44
  • 1
    The `fc` command accepts command line arguments, which are something different than console input, so redirection or piping cannot be used. What is wrong with temporary files? – aschipfl Jan 02 '21 at 09:06
  • @aschipfl Thanks so much! That's exactly what I concluded, but I hoped I was in error. I guess temporary files it is. The downside to them is performance (although piping has similar issues), but it is what it is. If you create an answer with the details provided, I will gratefully accept it. – RockPaperLz- Mask it or Casket Jan 02 '21 at 21:23

2 Answers2

1

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.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • Thank you! Great answer! This answer is a wonderfully written example of how one can write "I'm sorry, you are already doing it the best way, *and these are the specific details as to why*." Upvoted *and* accepted! – RockPaperLz- Mask it or Casket Feb 20 '21 at 10:18
  • @aschipfl nobody answered to my question yet [link](https://stackoverflow.com/questions/69709755/bat-batch-file-looping-over-multiple-python-files-and-compare-output-with-a-des). Your answer also applies to my question, right ? Is it just not possible what I'm trying to achieve? – Rabinzel Oct 26 '21 at 09:22
  • Yes, @Rabinzel, this answer also applies to your question; the `fc` command is not capable of reading its input data from a redirection handle, hence you will have to use a temporary file… – aschipfl Oct 26 '21 at 09:51
0

You have 10 file streams you can redirect. However you can only pipe program to program (which creates a temp file to do it).

user14797724
  • 109
  • 1
  • 3