How to run this Beyond Compare script from Powershell?

天涯浪子 提交于 2021-02-04 16:19:06

问题


currently I can use Beyond Compare script to output results to a file. You all were able to help me in figuring out how to check for differences in the result text file via Powershell. However, I do have another question. To get the results into a text file, Beyond Compare has you use a basic script and then run the script via cmd. My question is how do I run the script via Powershell instead of cmd? Below is the command used in cmd to run the script.

c:\Program Files\Beyond Compare 4>bcompare.exe @"C:\script.txt" "C:\test1" "C:\test" "C:\bcreport\report.txt"

The script that it is referencing is below.

load "%1" "%2"
expand all
folder-report layout:side-by-side options:display-mismatches output-to:"%3"

Thanks for any input. Getting this to work is all part of a much larger Powershell script I am working on. If I can get this to run from Powershell, it will save me a ton of time as I will be able to script something that takes hours.


回答1:


Unlike in cmd, an unquoted @ is a metacharacter in PowerShell; that is, it has special meaning[1].

To use @ verbatim, in order to pass it through to bcompare.exe in this case, escape it with `, which is PowerShell's escape character; i.e., use `@:

bcompare.exe `@"C:\script.txt" "C:\test1" "C:\test" "C:\bcreport\report.txt"

Alternatively, include the @ in the quoted string:

bcompare.exe "@C:\script.txt" "C:\test1" "C:\test" "C:\bcreport\report.txt"

Another alternative is to place --%, the so-called stop-parsing symbol before the arguments, as shown in Wasif Hasan's answer; doing so prevents PowerShell from interpreting the arguments before passing them on.
However, note that while this works as expected if all your arguments are literals, as in your case, in general it prevents you from using PowerShell variables and expressions as / in arguments, and can have other unexpected side effects - see this answer.


[1]

  • @ serves multiple syntactic purposes in PowerShell; with a " following the @, PowerShell thinks the argument is a here-string; since a here-string requires a multi-line definition, the command breaks due to a syntax error. @ before a variable name (e.g., @foo) performs splatting
  • This answer contrasts cmd's metacharacters with PowerShell's.
  • This answer has a comprehensive overview of how PowerShell parses unquoted command arguments.



回答2:


Or use --%, the stop-parsing symbol, if you're using powershell v3+:

bcompare.exe --% @"C:\script.txt" "C:\test1" "C:\test" "C:\bcreport\report.txt"

Or use shown solution by @mklement0



来源:https://stackoverflow.com/questions/60851830/how-to-run-this-beyond-compare-script-from-powershell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!