Running batch (cmd, bat) files like other registered commands
On Windows, which
for a batch file (bat, cmd) without the extension will return the full file name, extension included, and this is what is needed to be passed to Popen
.
However, sarge's internal find_command
discards the results of which
for bat and cmd files, because they have a registry shell\open\command
of "%1" %*
, rather than an executable so they don't match the regex.
I encounter this often when running ruby gem commands, such as the builtin gem
. On Ruby 193 windows , “gem” consists of a /bin/sh
script without extension for cygwin/msys users, and a gem.bat
for native usage. which correctly finds the latter, but then find_command discards it, so Command.run
tries to invoke gem
and fails.
Note that I very much do not want shell mode.
I believe the solution is to discard the regex and always do what shell\open\command
says to do , replacing "%1" with the results of which
.
However this would mean that there is a small test change required, as running hello
to invoke hello.py
will result in the Command
internals to use the result of which
(a full path) while the current approach keeps the shorter hello
. i.e. this would be a breaking change for anyone peeking inside of Command
and expecting the command to have a certain value.
Another approach is to special case .bat
and .cmd
, or special case any open
which has a value of "%1" %*
. That has no functional breaking changes, as it only fixes cases which were not previously functional
I have working solutions for both of the above approaches. Wanting direction on how to proceed.
Comments (2)
-
repo owner -
reporter It turns out that the above was optimistic. The use of
winreg.QueryKey
with a path of subkeys was also broken; I'm not sure how it ever worked, if at all. Perhaps it was ok in Python 2.6 ? Anyways, only a small part of it was functional, so I decided to go all out and fix it completely, with tests. https://bitbucket.org/vinay.sajip/sarge/pull-requests/8/fix-windows-registry-lookup - Log in to comment
It sounds like a PR for the second approach (no breaking changes) would be the way to go. Thanks!