Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run this Beyond Compare script from Powershell?

Tags:

powershell

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.

like image 290
user9641416 Avatar asked Mar 02 '23 15:03

user9641416


2 Answers

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.
like image 166
mklement0 Avatar answered Apr 04 '23 03:04

mklement0


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

like image 28
programmer365 Avatar answered Apr 04 '23 04:04

programmer365