Executable merge.exe (extracted from MSYS2) doesn't run on Windows

我是研究僧i 提交于 2021-02-10 13:07:11

问题


1. Problem explained

I need to run the merge tool (part of the GNU RCS project - Revision Control System) on Windows 10. These are the requirements:

  • STEP 1: The executable merge.exe must run in a native Windows cmd terminal.
  • STEP 2: The PATH env variable should not be modified.
  • STEP 3: The executable can be located in any arbitrary folder (of course, it's okay to put a bunch of dll's next to it if required).

It would lead us too far to explain why these requirements are so important. Please, just take them "as-is".


2. First trial: running the msys executable

I installed MSYS2 in C:/msys64 and found the executable at this location: C:/msys64/usr/bin/merge.exe. So time to try STEP1 ~ STEP3.

STEP 1
I can get it to work in a native Windows terminal if I add C:/msys64/usr/bin/ to the PATH env variable:

C:/Users/Kristof>merge.exe a.txt b.txt c.txt

huray!

STEP 2
Unfortunately, things go wrong when I don't modify the PATH env variable and invoke merge.exe by its full path instead:

C:/Users/Kristof>"C:/msys64/usr/bin/merge.exe" a.txt b.txt c.txt
/usr/bin/diff3: subsidiary program 'diff' not found

I don't get why this error appears. After all, the executables diff3.exe and diff.exe are both sitting next to merge.exe. Why can't they be found?

STEP 3
Well, STEP3 is obviously useless if I can't get the previous step to work first.


3. Other trials

3.1 Purdue binaries

You can find binaries for RCS here: https://www.cs.purdue.edu/homes/trinkle/RCShome/

I downloaded rcs57pc1.zip (1.2MB) from that website. Unfortunately, every attempt to run merge.exe fails with the following error message:

diff3.exe: subsidiary program failed

I tried the solutions offered on this StackOverflow post, but they won't work either:

RCS on Windows - rcsmerge always fails

 

3.2 ezwinports

I downloaded rcs-5.7-1.zip from: https://sourceforge.net/projects/ezwinports/files/

When running its merge.exe file, I get the following error:

diff3.exe: Unknown signal 0xEEEEEEEE
merge aborted

Indeed, I could not see a diff3.exe tool in the unzipped folder. So I copied diff3.exe and diff.exe from my MSYS installation (found at C:/msys64/usr/bin/) into the unzipped rcs-5.7-1 folder. No success. Same error message.

 

3.3 GnuWin32

The GnuWin32 project is known for its many Linux-to-Windows conversions of popular tools. I downloaded GnuWin32 (http://gnuwin32.sourceforge.net/) and did a full installation into C:/gnuwin32/. I searched through my C:/gnuwin32/ folder but cannot find a merge.exe tool anywhere. This is very weird, because the GNU RCS project is explicitely mentioned as a package from the GnuWin32 project here:

http://gnuwin32.sourceforge.net/packages/rcs.htm


回答1:


The solution is using diff3.exe directly instead of merge.exe:

You can put diff3.exe in any arbitrary directory, as long as you don't forget to copy these dll's:

  • msys-2.0.dll
  • msys-iconv-2.dll
  • msys-intl-8.dll

This is how to use the executable:

>diff3 -m myfile.txt ancestor.txt yourfile.txt

Unfortunately, it's still needed to add the folder to the PATH env variable. However, the actual usage goal was to call the executable from Python, so it can be done this way:

my_env = os.environ.copy()
my_env["PATH"] = "C:/merge/windows/;" + my_env["PATH"]
proc = subprocess.Popen(
    [
        merge_tool,
        "-m",
        myfile_path,
        ancestor_path,
        yourfile_path,
    ],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    env=my_env,
)

try:
    outs, errs = proc.communicate(timeout=15)
except TimeoutExpired:
    proc.kill()
    outs, errs = proc.communicate()
    return None
return outs.decode('utf-8').replace('\r\n', '\n')


来源:https://stackoverflow.com/questions/63290096/executable-merge-exe-extracted-from-msys2-doesnt-run-on-windows

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