Repository: pyenv-win/pyenv-win (language: python)

Issue:
Add original extension of script in rehash.
Basically just improving the rehash function so that the batch script of each shim includes the original extension of the script.
So, from this:
`call pyenv exec "&strDirBin&"%~n0 %*"`
to this:
`call pyenv exec "&strDirBin&baseName&"."&extension&" %*`

This is because Windows was not able to execute a batch file in the `Scripts` folder through pyenv without the .bat extension (not sure why). For example, if you install virtualenvwrapper-win, which creates batch files in the `Scripts` folder, than `pyenv exec Scripts/mkvirtualenv %*` will not work, because it is not able to recognize `Scripts/mkvirtualenv`  as a batch file (the original being `Scripts/mkvirtualenv.bat` ).
With this small modification, the shim of `mkvirtualenv `now looks like: `pyenv exec Scripts/mkvirtualenv.bat %*`, which correctly works. 
Also why not include the name directly in the shim rather than the "mysterious" `~n0`?
Note that this was not a problem in Linux.


Discussion / hints:
Thanks @sartorg for the bug report.
I think the fix is a one-liner. Here:

https://github.com/pyenv-win/pyenv-win/blob/79f446775c315ce8c22476ccf0bd7eeef7de1046/pyenv-win/bin/pyenv.bat#L59

Just add:

```bat
if exist %bindir%\%2.bat set cmddir=%bindir%\
```
@sartorg @dedale I am wondering why the CI status is still waiting..! 
___
After looking in Travis (CI) the PR never reached for the Testing, hmm why? No answer.

Fix patch:
diff --git a/README.md b/README.md
index fe933425..6abb3f2c 100644
--- a/README.md
+++ b/README.md
@@ -224,6 +224,7 @@ Now follow the steps to "[finish the installation](#finish-the-installation)".
 
 ### New in 2.64.9
 - Fix [#269] (https://github.com/pyenv-win/pyenv-win/issues/269): Migration from travis-ci to GitHub Actions
+- Fix `exec` shims for `bat` files.
 
 ### New in 2.64.8
 - Fix [#198](https://github.com/pyenv-win/pyenv-win/issues/198): [PEP 514](https://www.python.org/dev/peps/pep-0514/) support (64 bits only, excluding pypy).
diff --git a/pyenv-win/bin/pyenv.bat b/pyenv-win/bin/pyenv.bat
index 7c6e0549..dbe6109f 100644
--- a/pyenv-win/bin/pyenv.bat
+++ b/pyenv-win/bin/pyenv.bat
@@ -57,6 +57,7 @@ set cmdline=%cmdline:~5%
 set cmddir=
 if exist %bindir%\%2 set cmddir=%bindir%\
 if exist %bindir%\%2.exe set cmddir=%bindir%\
+if exist %bindir%\%2.bat set cmddir=%bindir%\
 set "path=%extrapaths%%path%"
 %cmddir%%cmdline%
 endlocal


Test patch:
diff --git a/tests/test_pyenv_feature_exec.py b/tests/test_pyenv_feature_exec.py
index 594a4932..8cee2446 100644
--- a/tests/test_pyenv_feature_exec.py
+++ b/tests/test_pyenv_feature_exec.py
@@ -142,6 +142,17 @@ def test_many_paths(self, setup):
                 assert paths[i].endswith(f'{v}{relative}')
                 i = i + 1
 
+    def test_bat_shim(self, setup):
+        pyenv = str(self.__class__.ctx.pyenv_path / "bin" / "pyenv.bat")
+        args = [pyenv, 'exec', 'Scripts/hello']
+        result = subprocess.run(args, capture_output=True, encoding="utf8")
+        stderr = result.stderr.strip("\r\n")
+        if stderr != '':
+            print(f'stderr: {stderr}')
+        # \x0c: generated by cls in cmd AutoRun
+        stdout = result.stdout.strip("\r\n\x0c")
+        assert stdout == "Hello world!"
+
 
 def pyenv_exec_help():
     return "Usage: pyenv exec <command> [arg1 arg2...]"
diff --git a/tests/test_pyenv_helpers.py b/tests/test_pyenv_helpers.py
index 33562f8a..e4061240 100644
--- a/tests/test_pyenv_helpers.py
+++ b/tests/test_pyenv_helpers.py
@@ -72,6 +72,8 @@ def create_scripts(path):
         os.mkdir(path)
         for exe in script_exes(ver):
             touch(path.joinpath(exe))
+        with open(path.joinpath('hello.bat'), "w") as batch:
+            print("@echo Hello world!", file=batch)
 
     for v in versions:
         ver = version.parse(v)