DhruvJ DhruvJ - 1 year ago 93
Python Question

cannot open files in beyond compare using python

I am making use of Beyond Compare 3 to see the difference between two XML files. I am willing to make a small python script which on executing will open files ready to compare in Beyond Compare tool.

So far I tried invoking BC3 from command line syntax as below and it works:

BCompare.exe "c:\Ref-2.xml" "c:\Cop-2.xml"

but when I try to execute same syntax from python script as shown below, It throws error

from subprocess import check_output
check_output('BCompare.exe "c:\Ref-2.xml" "c:\Cop-2.xml"', shell=True)

The error which is shown is:

raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command 'BCompare.exe "c:\Ref-2.xml" "c:\Cop-2.xml"' returned non-zero exit status 1

am I missing something? I tried different solutions to open command line instructions using this tutorial and many others but its not working.

Answer Source

Do something like this. Give Absolute path of .exe

check_output(absolute_path_of_beyond_compare "c:\Ref-2.xml"  "c:\Cop-2.xml"', shell=True)

I am able to open the Beyond Compare using following code:

from subprocess import check_output

check_output("BCompare.exe Test1.txt Test2.txt", shell=True)

where BCompare.exe path is added in path variable and Test1.txt Test2.txt are present in the same directory from where i have executed the program.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download