File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed
Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ defmodule Kernel.CLI do
271271 end
272272
273273 defp process_command ( { :script , file } , _config ) when is_binary ( file ) do
274- if exec = System . find_executable ( file ) do
274+ if exec = find_elixir_executable ( file ) do
275275 Code . require_file ( exec )
276276 :ok
277277 else
@@ -330,4 +330,19 @@ defmodule Kernel.CLI do
330330 { :error , "--compile : No files matched patterns #{ Enum . join ( patterns , "," ) } " }
331331 end
332332 end
333+
334+ defp find_elixir_executable ( file ) do
335+ if exec = System . find_executable ( file ) do
336+ # If we are on Windows, the executable is going to be
337+ # a .bat file that must be in the same directory as
338+ # the actual Elixir executable.
339+ case :os . type ( ) do
340+ { :win32 , _ } ->
341+ exec = Path . rootname ( exec )
342+ if File . regular? ( exec ) , do: exec
343+ _ ->
344+ exec
345+ end
346+ end
347+ end
333348end
Original file line number Diff line number Diff line change @@ -204,21 +204,23 @@ defmodule System do
204204 end
205205
206206 @ doc """
207- This functions looks up an executable program given
207+ This function looks up an executable program given
208208 its name using the environment variable PATH on Unix
209- and Windows.
209+ and Windows. It also considers the proper executable
210+ extension for each OS, so for Windows it will try to
211+ lookup files with `.com`, `.cmd` or similar extensions.
210212
211- If `command ` is a char list, a char list is returned.
213+ If `program ` is a char list, a char list is returned.
212214 Returns a binary otherwise.
213215 """
214216 @ spec find_executable ( char_list ) :: char_list | nil
215217 @ spec find_executable ( String . t ) :: String . t | nil
216- def find_executable ( command ) when is_list ( command ) do
217- :os . find_executable ( command ) || nil
218+ def find_executable ( program ) when is_list ( program ) do
219+ :os . find_executable ( program ) || nil
218220 end
219221
220- def find_executable ( command ) do
221- case :os . find_executable ( to_char_list ( command ) ) do
222+ def find_executable ( program ) do
223+ case :os . find_executable ( to_char_list ( program ) ) do
222224 false -> nil
223225 other -> list_to_binary ( other )
224226 end
You can’t perform that action at this time.
0 commit comments