The functions in this module are operating system-specific. Careless use of these functions results 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.
File operations used to accept filenames containing null characters (integer value zero). This caused the name to be truncated and in some cases arguments to primitive operations to be mixed up. Filenames containing null characters inside the filename are now rejected and will cause primitive file operations to fail.
Also environment variable operations used to accept names and values of environment variables containing null characters (integer value zero). This caused operations to silently produce erroneous results. Environment variable names and values containing null characters inside the name or value are now rejected and will cause environment variable operations to fail.
Currently null characters at the end of filenames, environment variable names and values will be accepted by the primitive operations. Such filenames, environment variable names and values are however still documented as invalid. The implementation will also change in the future and reject such filenames, environment variable names and values.
A string containing valid characters on the specific
OS for environment variable names using
A string containing valid characters on the specific
OS for environment variable values using
Assuming that environment variables has been correctly
set, a strings containing valid characters on the specific
OS for environment variable names and values using
All characters needs to be valid characters on the
specific OS using
Executes
Previous implementation used to allow all characters
as long as they were integer values greater than or equal to zero.
This sometimes lead to unwanted results since null characters
(integer value zero) often are interpreted as string termination.
Current implementation still accepts null characters at the end
of
Examples:
LsOut = os:cmd("ls"), % on unix platform
DirOut = os:cmd("dir"), % on Win32 platform
Notice that in some cases, standard output of a command when
called from another program (for example,
These two functions look up an executable program, with the
specified name and a search path, in the same way as the underlying
OS.
Returns a list of all environment variables.
Each environment variable is expressed as a single string on
the format
If Unicode filename encoding is in effect (see the
Returns the
If Unicode filename encoding is in effect (see the
Returns the
If Unicode filename encoding is in effect (see the
Returns the process identifier of the current Erlang emulator
in the format most commonly used by the OS environment.
Returns
Sets a new
If Unicode filename encoding is in effect (see the
On Unix platforms, the environment is set using UTF-8 encoding if Unicode filename translation is in effect. On Windows, the environment is set using wide character interfaces.
Enables or disables OS signals.
Each signal my be set to one of the following options:
Returns the current
This time is not a monotonically increasing time.
Returns the current
Calling
This time is not a monotonically increasing time.
Returns the current
Example of code formatting a string in format "DD Mon YYYY HH:MM:SS.mmmmmm", where DD is the day of month, Mon is the textual month name, YYYY is the year, HH:MM:SS is the time, and mmmmmm is the microseconds in six positions:
-module(print_time).
-export([format_utc_timestamp/0]).
format_utc_timestamp() ->
TS = {_,_,Micro} = os:timestamp(),
{{Year,Month,Day},{Hour,Minute,Second}} =
calendar:now_to_universal_time(TS),
Mstr = element(Month,{"Jan","Feb","Mar","Apr","May","Jun","Jul",
"Aug","Sep","Oct","Nov","Dec"}),
io_lib:format("~2w ~s ~4w ~2w:~2..0w:~2..0w.~6..0w",
[Day,Mstr,Year,Hour,Minute,Second,Micro]).
This module can be used as follows:
1> io:format("~s~n",[print_time:format_utc_timestamp()]). 29 Apr 2009 9:55:30.051711
OS system time can also be retreived by
Returns the current performance counter value in
Returns a performance counter that can be used as a very fast and high resolution timestamp. This counter is read directly from the hardware or operating system with the same guarantees. This means that two consecutive calls to the function are not guaranteed to be monotonic, though it most likely will be. The performance counter will be converted to the resolution passed as an argument.
1> T1 = os:perf_counter(1000),receive after 10000 -> ok end,T2 = os:perf_counter(1000). 176525861 2> T2 - T1. 10004
Returns the
On Unix,
On Windows,
Think twice before using this function. Use module
Deletes the environment variable
If Unicode filename encoding is in effect (see the
Returns the OS version. On most systems, this function returns a tuple, but a string is returned instead if the system has versions that cannot be expressed as three numbers.
Think twice before using this function. If you still need
to use it, always