Announcement

Collapse
No announcement yet.

Excel Datacompare via PowerShell in silent mode

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Excel Datacompare via PowerShell in silent mode

    Hello,

    I'm struggling to invoke BCompare.exe via the command line to compare 2 excel files, without the GUI being displayed.

    The command I am using is as follows. I have tried it with the BComp.com, but again that is displaying a GUI. If we use the /qc option instead of the /fv option then we do not get the GUI. However, we find that executing the script when logged in on the machine gives different results than when invoking the very same script via Invoke-Command. Any suggestions

    $ps = new-object System.Diagnostics.Process
    $ps.StartInfo.Filename = "C:\Program Files (x86)\Beyond Compare 3\BCompare.exe"
    $ps.StartInfo.Arguments = "/silent /fv=""Data Compare"" ""$filePathA"" ""$filePathB"""
    $ps.start() |out-null
    $ps.WaitForExit()

  • #2
    Hello,

    To avoid the GUI, you would need to use either /quickcompare or @script.txt. /quickcompare will generate a return code based on the file input. @script.txt will run the attached @script.txt file and execute the commands within (in this case, probably to generate a text-report would be what you need).

    /quickcompare or /qc would use the default compare method and default settings of the current Windows user account running the command. When testing the graphical interface and your integrated solution, please double check that the same Windows User (%AppData%) is in use. Another strategy is to create a Portable Install to C:\Tools\Beyond Compare 4\ and use this instead. Any user running this install will all share settings, and may be an easier solution for you to troubleshoot a difference in comparison results.


    @script.txt is similarly using the default comparison method, but returns a little more info than just an errorcode. You can run:
    bcompare.exe "@c:\scripts\script.txt" "c:\file1.txt" "c:\file2.txt" "c:\scripts\reportoutput.html"

    where script.txt is:
    text-report layout:side-by-side output-to:"%3" "%1" "%2" output-options:html-color

    Please note that you would pick either /qc or @script, and not both, depending on your automated needs.
    Aaron P Scooter Software

    Comment


    • #3
      Aaron, executing this on BC3 gives the following exception??

      C:\Windows\system32>"C:\Program Files (x86)\Beyond Compare 3\BCompare.exe" "@c:\
      tmp\bscript.txt" "c:\tmp\Ken.xls" "c:\tmp\Ryu.xls" "c:\tmp\Report.html"

      13/02/2017 16:20:31 Fatal Scripting Error: Unexpected argument(s) "c:\tmp\Ken.xls"

      Comment


      • #4
        Hello,

        And could you include the full text of your bcscript.txt? A small typo, whitespace, or syntax error could result in errors.
        Aaron P Scooter Software

        Comment


        • #5
          This is the contents

          text-report layout:side-by-side output-to:"%3" "%1" "%2" output-options:html-color

          I have also now created a Portable install to ensure we are not dealing with Profiles and am still getting the same issue when being invoked via powershell Invoke-Command

          Comment


          • #6
            Hello,

            Ah, thanks. I missed the order in my example. It should be:
            text-report layout:side-by-side output-to:"%3" output-options:html-color "%1" "%2"

            with the file name input parameters always trailing the very end.
            Aaron P Scooter Software

            Comment


            • #7
              Aaron,

              Thanks for that, thats has fixed the issue. However, its still looks like its doing a text compare, when I look at the output in the html file.

              I then started to change the content of bscript.txt to the following, however I receive a 107 script error. Can you see anything wrong with the below. I need to ensure that the xls files are compared using a data compare

              data-report layout:summary options:ignore-unimportant title:"Data Report" output-to:"%3" output-options:html-color "%1" "%2"

              Execution
              "C:\Beyond Compare 3\BCompare.exe" "@c:\tmp\bscript.txt" "c:\tmp\Ken.xls" "c:\tmp\Ryu.xls" "c:\tmp\Report.html"

              Thanks

              Paul

              Comment


              • #8
                Hello,

                That script looks ok. If you run it from the Windows Command Line (without /silent), what does the script dialog show when it pops up the Script window/log pane?
                Aaron P Scooter Software

                Comment


                • #9
                  Hello,

                  On the box itself it seems to run fine, I seem to be experiencing the issue when running remotely then I receive the 107 script error. I'll investigate further to see what it may be.

                  Thanks for your help so far.

                  Paul

                  Comment


                  • #10
                    Hello,

                    Is the Beyond Compare install remote, or is it accessing remote locations as a local install?

                    Your current Windows User Account (%AppData%) controls settings and registration by default. Using a Portable Install (which the setup.exe can create in C:\Tools\Beyond Compare 4\) might help if there are access problems running as a different user or running as a remote user running a remote install, or something similar.
                    Aaron P Scooter Software

                    Comment


                    • #11
                      Aaron,

                      I have changed it to a Portable install, and I have also checked that the powershell command that invokes the BCompare.exe is running with elevated permissions, which it is.

                      Contents of ReportComp.ps1

                      function Compare-FilesBeyondCompare() {
                      param([Parameter(Mandatory=$true)]$filePathA,[Parameter(Mandatory=$true)]$filePathB)

                      $ps = new-object System.Diagnostics.Process
                      $ps.StartInfo.Filename = "C:\Beyond Compare 3\BCompare.exe"
                      $ps.StartInfo.Arguments = "/silent /fv=""Data Compare"" ""@c:\tmp\bscript.txt"" ""$filePathA"" ""$filePathB"" ""c:\tmp\Report.html"""
                      #$ps.StartInfo.Arguments = "/qc ""$filePathA"" ""$filePathB"""
                      $ps.start() |out-null
                      $ps.WaitForExit()

                      $rul = $ps.ExitCode -eq 2
                      $exitCode = $ps.ExitCode

                      Write-Host "$filePathA"
                      Write-Host "rul=$rul, exitCode=$exitCode"


                      <#$bin -eq $True -or $rul -eq $True#>
                      $exitCode -lt 13

                      }
                      Compare-FilesBeyondCompare "c:\tmp\Ken.xls" "C:\tmp\Ryu.xls"

                      Contents of bscript.txt
                      data-report layout:summary options:ignore-unimportant title:"Data Report" output-to:"%3" output-options:html-color "%1" "%2"

                      Using a powershell console on a different machine I then invoke ReportComp.ps1 script, the response of executing this PowerShell script from a remote machine is different than running the same ReportComp.ps1 from the machine that the script is located on.
                      Invoke-Command -ComputerName xxxxxxxx -ScriptBlock { c:\ReportComp.ps1 }

                      Are you able to try this from your end?

                      Comment


                      • #12
                        Hello,

                        I suggest removing /silent for troubleshooting purposes. Also, remove /fv=data, as that isn't used in conjunction with a @script call.

                        I don't have much experience with Powershell, and don't have any experience attempting to run it remotely, so I don't think I'll be much help from that angle. If BC4 is called and using the same set of settings in a Portable Install (with BCState.xml and other .xml setting files in the same folder as BCompare.exe), then it should show the same results from the generated data-report script. Are you running the latest BC3.3.13 release?:
                        http://www.scootersoftware.com/download.php?zz=dl3_en

                        To help test if each Powershell call is accessing BC4 properly and has access to the correct settings folder, change the script to load a saved folder compare session by name. Create the Folder Compare session in the graphical interface, and give it a custom name: "saved Folder session". The script can then load by name:
                        log verbose "c:\logs\bclog.txt"
                        load "saved Folder session"

                        If the log shows success, then that script call is using the same settings. If the session name load fails, then that call is accessing a different settings folder location, due to the nature of how you are calling it. A Portable Install should share settings with any Windows User that accesses that Portable Install. Can you verify that BCState.xml and other settings files are in the install folder?
                        Aaron P Scooter Software

                        Comment

                        Working...
                        X