os(3)

MODULE
os - Operating System Specific Functions

DESCRIPTION

The functions in this module are operating system specific. Careless use of these functions will result in programs that will only run on a specific platform. On the other hand, with careful use these functions can be of help in enabling a program to run on most platforms.

EXPORTS

cmd(Command) -> string()

    Types
        Command = string() | atom()

    Executes Command in a command shell of the target OS and returns the result as a string. This function is a replacement of the previous unix:cmd/1; on a Unix platform they are equivalent.

    Examples:
    LsOut = os:cmd("ls"), % on unix platform
    DirOut = os:cmd("dir"), % on Win32 platform

find_executable(Name) -> Filename | false
find_executable(Name, Path) -> Filename | false

    Types
        Name = string()
        Path = string()
        Filename = string()

    These two functions look up an executable program given its name and a search path, in the same way as the underlying operating system. find_executable/1 uses the current execution path (i.e., the environment variable PATH on Unix and Windows). Path, if given, should conform to the syntax of execution paths on the operating system. The absolute filename of the executable program Name is returned, or false if the program was not found.

getenv(VarName) -> Value | false

    Types
        Varname = string()
        Value = string()

    Returns the Value of the environment variable VarName, or false if the environment variable is undefined.

getpid() -> Value

    Types
        Value = string()

    Returns the process identifier of the current Erlang emulator in the format most commonly used by the operating system environment. Value is returned as a string containing the (usually) numerical identifier for a process. On Unix, this is typically the return value of the getpid() system call. On VxWorks, Value contains the task id (decimal notation) of the erlang task. On Windows, the process id as returned by the GetCurrentProcessId() system call is used.

type() -> {Osfamily,Osname} | Osfamily

    Types
        Osfamily = atom() = win32 | unix | vxworks
        Osname = atom()

    Returns the Osfamily and, in some cases, Osname of the current operating system.

    On Unix, Osname will be same string that uname -s returns, but in lower case. For instance, on Solaris 1 and 2, the atom sunos will be returned.

    In Windows, Osname will be either nt (on Windows NT), or windows (on Windows 95). On VxWorks Osfamily alone is returned, i.e. the atom vxworks.

  Note:

Think twice before using this function. Use the filename module if you want to inspect or build file names in a portable way. Avoid matching on the Osname atom.

version() -> {Major, Minor, Release} | VersionString

    Types
        Major = Minor = Release = integer()
        VersionString = string()

    Returns the operating system version. On most systems, this function returns a tuple, but a string will be returned instead if the system has versions which cannot be expressed as three numbers.

  Note:

Think twice before using this function. If you still need to use it, always call os:type() first.

AUTHOR
Bjorn Gustavsson - bjorn@erix.ericsson.se