0

I have a batch file where a python script data.py is called 33 times and tests some data. The input to test is in test.a

The output of this script should be compared to a file with the desired output content. The goal is to have no differences in all 33 test loops (--> the python script works properly)

@echo off
setlocal enableDelayedExpansion

for /l %%N in (101,1,133) do (
    set "n=%%N"
    echo Testing !n:~-2!
    < test\test!n:~-2!\test.a python data.py 
    > test\test!n:~-2!\output.txt | 
    fc test\test!n:~-2!\output.txt test\test!n:~-2!\test.b   
)

Is there a way to compare the output of the .py with test.b WITHOUT generating the output.txt file ?

And another little problem. These output files are exactly the same, in output.txt it is empty, in test.b the whole solution gets displayed. Why? If there is no difference it shouldn't display anything right?

Vergleichen der Dateien TEST\TEST01\output.txt und TEST\TEST01\TEST.B
***** TEST\TEST01\output.txt
***** TEST\TEST01\TEST.B
s1|s2|s1|s2
*****
Rabinzel
  • 7,757
  • 3
  • 10
  • 30
  • 2
    Why not use `For /L %%G In (101,1,133) Do (`, `Set "n=%%G"`, remove the next `set` line and replace the instances of `!y!` with `!n:~-2!`? – Compo Oct 25 '21 at 14:34
  • oh, that's a nice workaround for the 01, 02, 03 thingy. Thanks! – Rabinzel Oct 25 '21 at 14:41
  • The `fc` command does not read from a redirection handle, so you will have to use a file. Why is that a problem? – aschipfl Oct 26 '21 at 09:53
  • Concerning the other little problem: `fc` returns the paths of the compared files and `FC: no differences encountered` for equal files, hence the output is never empty. Your sample result shows differences, which I believe are caused by a different number of final line-breaks in your files… – aschipfl Oct 26 '21 at 09:57
  • @aschipfl if that's the case, I would see the differences when opening both files with notepad++, wouldn't I? I just did and they look 100% equal. I also just tried to change my output.txt to output.b to get same file format but no success. Any idea how I can fix this? – Rabinzel Oct 26 '21 at 10:21
  • Hm… is the encoding of the files identical? What happens if you do a binary comparison by `fc /B`? – aschipfl Oct 26 '21 at 11:08
  • yes. Both UTF-8. I just changed to `fc /B` ...same result. – Rabinzel Oct 26 '21 at 11:20
  • @aschipfl hm I figured it out. In my batch I need to remove the pipe and run the FC command on its own on the both files. Since I'm not able to redirect the output to fc anyway this even makes more sense to have it as its own command.... there is only one big thing.. WHY was it wrong before? – Rabinzel Oct 26 '21 at 12:06

0 Answers0