Running batch (cmd, bat) files like other registered commands

Issue #45 new
John Mark Vandenberg created an issue

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.batfor 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.pywill 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 openwhich 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)

  1. Vinay Sajip repo owner

    It sounds like a PR for the second approach (no breaking changes) would be the way to go. Thanks!

  2. Log in to comment