Monday 30 May 2016

Haskell: findExecutable : Get the path of given executable

System.Directory module provides findExecutable function which return the path of given executable file. Following is the signature of the findExecutable function.

Prelude System.Directory> :t findExecutable
findExecutable :: String -> IO (Maybe FilePath)

Observe the signature, it takes a executable file name as input and return Just Path, if the executable exists, else return Nothing.


Prelude System.Directory> findExecutable "java"
Just "/usr/bin/java"
Prelude System.Directory> findExecutable "cabal"
Just "/usr/local/bin/cabal"
Prelude System.Directory> 
Prelude System.Directory> findExecutable "krishna"
Nothing

Note
findExecutable searcher for the file in the directories listed in system PATH. On Windows, findExecutable calls the Win32 function SearchPath.





Previous                                                 Next                                                 Home

No comments:

Post a Comment