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
271
271
end
272
272
273
273
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
275
275
Code . require_file ( exec )
276
276
:ok
277
277
else
@@ -330,4 +330,19 @@ defmodule Kernel.CLI do
330
330
{ :error , "--compile : No files matched patterns #{ Enum . join ( patterns , "," ) } " }
331
331
end
332
332
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
333
348
end
Original file line number Diff line number Diff line change @@ -204,21 +204,23 @@ defmodule System do
204
204
end
205
205
206
206
@ doc """
207
- This functions looks up an executable program given
207
+ This function looks up an executable program given
208
208
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.
210
212
211
- If `command ` is a char list, a char list is returned.
213
+ If `program ` is a char list, a char list is returned.
212
214
Returns a binary otherwise.
213
215
"""
214
216
@ spec find_executable ( char_list ) :: char_list | nil
215
217
@ 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
218
220
end
219
221
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
222
224
false -> nil
223
225
other -> list_to_binary ( other )
224
226
end
You can’t perform that action at this time.
0 commit comments