No announcement yet.

How to add grammar or rules via commandline

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to add grammar or rules via commandline


    I would like to compare pdf files from a linux command line and eventually in a script.

    The files have many differences and it is certain that the rules for unimported text to ignore will grow with time.

    I managed to add grammar and rules via the gui and found posts telling to add the rules via GUI first.
    Since the rules have to be used identically on different test servers it is to cumbersome to maintain the rules on each instance of bcompare manually and when running the comparison through a script within a build the manual update is not possible.

    Therefore I'm looking for a way to define a file type and add new rules rsp regular expressions from the command line.
    The nice way would be to define a file type, then write a file with all rules for text to be ignored and import the rules from that file to bcompare.

    Is there a way how to do this?



  • #2
    The first thing to note is that Beyond Compare for Linux requires an X-Window session, even for scripting. This means it will not run as a cron job or in an SSH session without a GUI. The Windows version of Beyond Compare doesn't have the GUI requirement for scripts.

    It isn't possible to define grammar and importance with scripting commands or command line arguments. As a workaround, you'll need to define file format settings interactively, then set importance settings for the default session. Default session settings will affect scripted comparisons.

    To set default session settings, load the Text Compare. Click the Rules toolbar button (referee icon). In the Importance tab, check grammar elements to make them important or unimportant. Before clicking OK to close the dialog, change the dropdown at the bottom of the dialog from Use for this view only to Also update session defaults.

    Settings are stored as XML in $HOME/.config/bcompare/, you can copy the XML files to deploy them to other users/machines.

    As an alternative to copying XML files to deploy settings, export settings to a file using Tools > Export Settings, then import them using the -silent command line argument.

    Example command-line import of settings:
    bcompare -silent BCSessions.bcpkg
    Chris K Scooter Software


    • #3
      Thanks for your reply!

      If I understand you comment right, I could create the rules and grammar on the BeyondCompare instance eg on my local computer, save to the default session and the export it.
      Then I would import these settings on the command line within a X window session.

      However I don't fully understand the impact of the xwindow session. When running within a build process, I need to automatically generate a diff file based on 2 files to compare.
      In the build there will be a set of pdfs produced that I want to compare to an earlier version eg from the last build or from the last release in production.

      So I would need to 'stuff' 2 file names on the commandline and have a diff file automatically saved as output, eg as pdf.

      Is this possible at all without manual interaction? If not would you know any way or tool how to do this?


      • #4

        BC4 supports a scripting mode (bcompare @scriptfile.txt) which launches in an automated mode, executes the commands in script. Documentation for this mode is found in the Help file under Using Beyond Compare -> Automating with Script chapter, or in the main Scripting Reference chapter. It is important to note this mode also requires X-Windows (a graphical environment) in order to launch, even though there is no direct user interaction, due to BC4's dependencies.

        This mode also accepts parameters on the command line to inject as variables in the script, such as:
        bcompare @script.txt "filename1.txt" "filename2.txt" "fileout.txt"

        where in script they can reference with "%1" "%2" "%3" etc:
        text-report layout:patch output-to:"%3" "%1" "%2"
        Last edited by Aaron; 01-Nov-2018, 10:37 AM. Reason: update code tag
        Aaron P Scooter Software