No announcement yet.

New Updates in Windows WSL

  • Filter
  • Time
  • Show
Clear All
new posts

  • New Updates in Windows WSL

    New features deployed with the Linux subsystem for windows should now make it possible for BC4 to work with the WSL.

    It is now possible to invoke EXE's from bash. For example you can activate BC4 like so:

    [email protected]:~$ /mnt/c/Program\ Files/Beyond\ Compare\ 4/bcomp.exe
    Notice the escaped spaces in the above command. Simply copy and paste this and you'll see that BC4 opens.

    The opposite is now true as well:
    C:\temp> wsl sudo apt-get update
    The above invokes the command just as if you were in bash itself.

    Do these changes warrant looking into this again?

  • #2
    To clarify earlier posts about Windows Subsystem for Linux (WSL), Scooter Software doesn't officially support running Beyond Compare for Linux in WSL. Microsoft also doesn't officially support running graphical (X-Window) applications using WSL. You might be able to make BC4 Linux work if you run an X-Window client, but it isn't a configuration we test, so we can't guarantee it will work. See the previous forum thread Installing Linux BC4 under WSL for a possible method to run BC4 Linux in WSL.

    Beyond Compare for Windows doesn't support Linux/Unix style paths, so that's the main issue with launching it from Git in WSL. I haven't had time to test the instructions yet, but the blog post WSL, git, and Beyond Compare might point you in the direction of a working Git in WSL + BC 4 Windows configuration.
    Chris K Scooter Software


    • #3
      The blog post above that Chris mentioned, WSL, git and Beyond Compare worked great with the exception that I had to modify the alias to execute git difftool -y --dir-diff --no-symlinks --tool=BCompare


      • #4
        I just added a comment in regards to using Beyond Compare with Windows / Bash. Basically to solve the problem I used a handy script to convert the file paths from POSIX to Windows which could then be given to Beyond Compare. I just need to tinker a little so that the /tmp/ path was converted correctly (see issue #7 on that github repo).


        • #5
          Just adding my two cents here. The only blocker issue for me not to buy BC4 currently is the way it is broken with WSL.

          WSL currently supports starting Windows apps from Linux, and starting Linux apps from Windows. It also supports accessing Linux files from Windows, and accessing Windows files from Linux.

          I store my git repositories in Linux filesystem (in WSL), and regularly run git difftool or git mergetool from there, and also manually launch diff tools from there.

          In p4merge for example, or most other Windows apps, I can just give the normal linux path as an argument and everything works. Like this:
          ~$ p4merge.exe fileA fileB
          ~$ p4merge.exe /tmp/fileA /tmp/fileB
          However for some reason the first one works but the last one does not work with BC4. The first slash breaks it, all relative paths work but using any absolute path doesn't work. This makes it difficult to launch BC4 from scripts or git.

          I know WSL isn't officially supported by BC4, but BC4 really is the only Windows app I've noticed to not work when launched from WSL with absolute path to a linux file as an argument, so this seems like a bug in BC4.

          The workaround at blog post "WSL, git, and Beyond Compare" doesn't work for me, as I don't store my git repository in Windows filesystem.


          • #6
            Thanks for the feedback and additional example cases. I'll add this usecase to our wishlist entry on the subject. Does the above helper script to convert paths help?
            Aaron P Scooter Software


            • #7
              Thanks for a quick reply. If you are referring to - no, I don't think so. If I understand correctly it should convert the path if the file actually is on Windows FS but command is launched from Linux, which means this as an example:
              Actual storage of an example file:
              Path shown in Linux:
              Command to run in Linux:
              BComp.exe $(wslpath /mnt/c/fileA)
              Which would translate to
              BComp.exe C:\fileA
              So when working with Windows files from Linux, this script converts the paths to native Windows paths.

              However in my use case the files are in Linux filesystem, not in Windows. WSL natively converts those paths to Windows paths under \\wsl$\ so they shouldn't need any other conversion. \\wsl$\ is the new feature in recent Windows versions which allows Windows apps to see files under the Linux filesystem. It should show up as a kind of a network share. More info on that:


              • #8
                Ah, thanks for the clarification and helpful resource links. I'll add these references to our tracker as well.
                Aaron P Scooter Software


                • #9
                  An update, I managed to get it working using the built-in wslpath command which comes with new WSL versions!

                  My git config on WSL linux side:

                  difftool.bc3.cmd=BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)"
                  mergetool.bc3.cmd=BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" "$(wslpath -aw $BASE)" "$(wslpath -aw $MERGED)"
                  BComp.exe is in my $PATH. I'm using WSL2 on Windows version 2004 (build 19041), and this works both inside the WSL filesystem and also for the mounted Windows filesystem.

                  The new wslpath -aw converts the Linux paths like this:
                  $ wslpath -aw /home/
                  And Windows paths like this:
                  $ wslpath -aw /mnt/c/Users/
                  This makes them both work perfectly with the Windows version of BC when launched from Linux.


                  • #10
                    The git config from tumik works great for me!
                    wslpath -aw makes the paths come out right.
                    Please add the WSL info to the support page.

                    - I'm using WSL1 on Windows version 20H2 (build 19042.746)
                    - I've got C:\Program Files\Beyond Compare 4 in my Windows path...
                    - /mnt/c/Program Files/Beyond Compare 4 appears in my Linux path

                    After configuring the command and making bc3 the default for difftool, it launches great for me.
                    $ git config --global difftool.bc3.cmd 'BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)"'
                    $ git config --global diff.tool bc3
                    $ git difftool


                    • #11
                      Tumik and Kyle's instructions work for me too in WSL 2.

                      I have not got the BC directory in my Windows path, so the [difftool "bc3"] section in my global git config looks like this:
                      [difftool "bc3"]
                          cmd = '/mnt/c/Program Files (x86)/Beyond Compare 4/BComp.exe' \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $REMOTE)\"
                      (Tip: to get your global git config for WSL up in your editor, use the git config --global -e command and it will open in your configured editor)

                      Type git difftool -t bc3, and BC will fire up.

                      To make BC the default as Kyle did I used git config --global diff.tool bc3

                      Now I can type git difftool and BC will start up as the default.

                      To complete the picture, here's a screenshot to show how BC opens up the files inside WSL 2 via a network share (note, "shrop-bot-soc" is the name of my WSL distro - yours will more likely be something like "Ubuntu"):

                      Click image for larger version

Name:	Dn2WBer.png
Views:	1152
Size:	34.6 KB
ID:	85437

                      Some more background on how this magic works:



                      Microsoft’s Craig Loewen explains how it works: Rather than accessing these files directly, Windows runs a Plan 9 server as part of the WSL software in the background. Windows 10 has “a Windows service and driver that acts as the client and talks to the Plan9 server.” That server translates your file operations and handles Linux metadata such as file permissions, ensuring everything works properly even when you access a file with a Windows tool. But that’s just the complicated stuff that happens in the background, and you don’t have to think about it.
                      In other words, BC works seamlessly with files inside WSL. Happy days.


                      • #12
                        Thank you guys for the information.
                        Initially I've set up Windows BC4 as you described above and it worked like a charm with git but... it's inconvenient to compare arbitrary files (not tracked by git) because it requires adding "/mnt/c/Program Files/Beyond Compare 4" to the PATH environment variable and it does not work with absolute paths (I cannot just type "BComp.exe /absolute/path/file1 file2", I have to use wslpath again).
                        So I've ended up with installing BC4 for Linux, as Chris suggested, and removed all those configs and now I can just type lowercase "bcompare any_path_1 any_path_2" to compare any files on Linux. Of course, to make it work I've installed X-Server (vcxsrv) on Windows side and set DISPLAY env var accordingly on Linux side, but I had to do this anyway to be able to execute other GUI Linux apps.


                        • #13
                          On the other hand, Windows BC4 looks prettier than Linux BC4 under WSL, so I will use WSL config to launch Windows BC4 with git operations.
                          And I will leave Linux BC4 installation to use it for arbitrary files comparison.
                          Last edited by FourLegsDriveCat; 14-Jun-2022, 12:10 PM.