@@ -81,7 +81,7 @@ data EnvOverride = EnvOverride
8181 , eoStringList :: [(String , String )] -- ^ Environment variables as association list
8282 , eoPath :: [FilePath ] -- ^ List of directories searched for executables (@PATH@)
8383 , eoExeCache :: IORef (Map FilePath (Either ReadProcessException (Path Abs File )))
84- , eoExeExtension :: String -- ^ @""@ or @" .exe"@, depending on the platform
84+ , eoExeExtensions :: [ String ] -- ^ @[""]@ on non-Windows systems, @["", " .exe", ".bat"]@ on Windows
8585 , eoPlatform :: Platform
8686 }
8787
@@ -114,7 +114,10 @@ mkEnvOverride platform tm' = do
114114 , eoStringList = map (T. unpack *** T. unpack) $ Map. toList tm
115115 , eoPath = maybe [] (FP. splitSearchPath . T. unpack) (Map. lookup " PATH" tm)
116116 , eoExeCache = ref
117- , eoExeExtension = if isWindows then " .exe" else " "
117+ , eoExeExtensions =
118+ if isWindows
119+ then [" " , " .exe" , " .bat" , " .com" ]
120+ else [" " ]
118121 , eoPlatform = platform
119122 }
120123 where
@@ -336,10 +339,7 @@ findExecutable :: (MonadIO m, MonadThrow n)
336339 -> String -- ^ Name of executable
337340 -> m (n (Path Abs File )) -- ^ Full path to that executable on success
338341findExecutable eo name0 | any FP. isPathSeparator name0 = do
339- let names0
340- | null (eoExeExtension eo) = [name0]
341- -- Support `stack exec foo/bar.exe` on Windows
342- | otherwise = [name0 ++ eoExeExtension eo, name0]
342+ let names0 = map (name0 ++ ) (eoExeExtensions eo)
343343 testNames [] = return $ throwM $ ExecutableNotFoundAt name0
344344 testNames (name: names) = do
345345 exists <- liftIO $ D. doesFileExist name
@@ -357,10 +357,7 @@ findExecutable eo name = liftIO $ do
357357 let loop [] = return $ Left $ ExecutableNotFound name (eoPath eo)
358358 loop (dir: dirs) = do
359359 let fp0 = dir FP. </> name
360- fps0
361- | null (eoExeExtension eo) = [fp0]
362- -- Support `stack exec foo.exe` on Windows
363- | otherwise = [fp0 ++ eoExeExtension eo, fp0]
360+ fps0 = map (fp0 ++ ) (eoExeExtensions eo)
364361 testFPs [] = loop dirs
365362 testFPs (fp: fps) = do
366363 exists <- D. doesFileExist fp
0 commit comments