无法使用 python 打开 beyond compare 文件
cannot open files in beyond compare using python
我正在使用 Beyond Compare 3 查看两个 XML 文件之间的差异。我愿意制作一个小 python 脚本,该脚本在执行时将打开准备好在 Beyond Compare 工具中进行比较的文件。
到目前为止,我尝试从命令行语法调用 BC3,如下所示,它有效:
BCompare.exe "c:\Ref-2.xml" "c:\Cop-2.xml"
但是当我尝试从 python 脚本执行相同的语法时,如下所示,它会抛出错误
from subprocess import check_output
check_output('BCompare.exe "c:\Ref-2.xml" "c:\Cop-2.xml"', shell=True)
显示的错误是:
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
我错过了什么吗?我尝试了不同的解决方案来使用 this 教程和许多其他方法打开命令行指令,但它不起作用。
做这样的事情。给出 .exe 的绝对路径
check_output(absolute_path_of_beyond_compare "c:\Ref-2.xml" "c:\Cop-2.xml"', shell=True)
我可以使用以下代码打开 Beyond Compare:
from subprocess import check_output
check_output("BCompare.exe Test1.txt Test2.txt", shell=True)
其中 BCompare.exe 路径添加到路径变量中,Test1.txt Test2.txt 出现在我执行程序的同一目录中。
使用安装 beyond compare 的确切路径或将其添加到您的环境变量 "Path"。
如果使用确切的安装路径,请在“\"C:\Program Files\Beyond Compare 4\BCompare.exe\" test1.txt test2.txt”行中添加一些内容
\" 可以读取 path
中的特殊字符和额外空格
import subprocess
subprocess.Popen([r"C:\Program Files\Beyond Compare 4\BCompare.exe", r"FullFilePath_File1", r"FullFilePath_File2"])
我在我的电脑上测试过,它有效。
我没有结帐,而是使用 Popen。
我通过安装 Anaconda3-5.2.0-Windows-x86_64
使用 Jupyter notebook
Python版本=3.6.5
我正在使用 Beyond Compare 3 查看两个 XML 文件之间的差异。我愿意制作一个小 python 脚本,该脚本在执行时将打开准备好在 Beyond Compare 工具中进行比较的文件。
到目前为止,我尝试从命令行语法调用 BC3,如下所示,它有效:
BCompare.exe "c:\Ref-2.xml" "c:\Cop-2.xml"
但是当我尝试从 python 脚本执行相同的语法时,如下所示,它会抛出错误
from subprocess import check_output
check_output('BCompare.exe "c:\Ref-2.xml" "c:\Cop-2.xml"', shell=True)
显示的错误是:
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
我错过了什么吗?我尝试了不同的解决方案来使用 this 教程和许多其他方法打开命令行指令,但它不起作用。
做这样的事情。给出 .exe 的绝对路径
check_output(absolute_path_of_beyond_compare "c:\Ref-2.xml" "c:\Cop-2.xml"', shell=True)
我可以使用以下代码打开 Beyond Compare:
from subprocess import check_output
check_output("BCompare.exe Test1.txt Test2.txt", shell=True)
其中 BCompare.exe 路径添加到路径变量中,Test1.txt Test2.txt 出现在我执行程序的同一目录中。
使用安装 beyond compare 的确切路径或将其添加到您的环境变量 "Path"。 如果使用确切的安装路径,请在“\"C:\Program Files\Beyond Compare 4\BCompare.exe\" test1.txt test2.txt”行中添加一些内容 \" 可以读取 path
中的特殊字符和额外空格import subprocess
subprocess.Popen([r"C:\Program Files\Beyond Compare 4\BCompare.exe", r"FullFilePath_File1", r"FullFilePath_File2"])
我在我的电脑上测试过,它有效。
我没有结帐,而是使用 Popen。
我通过安装 Anaconda3-5.2.0-Windows-x86_64
Python版本=3.6.5