Loading ...
Sorry, an error occurred while loading the content.

Re: "ocaml_beginners"::[] Directory in which executable is found?

Expand Messages
  • Richard Jones
    ... On Unix this isn t possible in general. For example, the executable might have been deleted. However there are various heuristics you can use to try to
    Message 1 of 7 , Nov 6, 2004
    • 0 Attachment
      On Fri, Nov 05, 2004 at 02:52:06PM -0300, andrew cooke wrote:
      > How do I find the directory in which the executable is located (I want to
      > be able to read data from files that are part of my program's install
      > directory).

      On Unix this isn't possible in general. For example, the executable
      might have been deleted. However there are various heuristics you can
      use to try to find the executable. This discussion applies equally
      well to any Unix program.

      (1) On Linux, follow /proc/self/exe which is a symlink which may
      point to the executable.

      (2) On Unix in general, look at the first command line argument
      (Sys.argv.(0)) which will either be a full path which may be the
      executable (but may not) or will be a relative path which can be
      looked up by examining each element of $PATH (Sys.getenv "PATH") in
      turn.

      All of these methods may fail if the program was called in a strange
      way, executable deleted or replaced, etc.

      Rich.

      --
      Richard Jones. http://www.annexia.org/ http://www.j-london.com/
      >>> http://www.team-notepad.com/ - collaboration tools for teams <<<
      Merjis Ltd. http://www.merjis.com/ - improving website return on investment
      Write Apache modules in OCaml - http://www.merjis.com/developers/mod_caml


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.