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.
Options for
The maximum size of the data returned by the
Executes
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,
The maximum size of the data returned by the
> os:cmd("cat /dev/zero", #{ max_size => 20 }).
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
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.
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