This class provides access to various base functions of system platforms.
Look in the sys
package for more system APIs.
Static methods
staticargs():Array<String>
Returns all the arguments that were passed in the command line. This does not include the interpreter or the name of the program file.
(java)(eval) On Windows, non-ASCII Unicode arguments will not work correctly.
(cs) Non-ASCII Unicode arguments will not work correctly.
staticcommand(cmd:String, ?args:Array<String>):Int
Runs the given command. The command output will be printed to the same output as the current process.
The current process will block until the command terminates.
The return value is the exit code of the command (usually 0
indicates no error).
Command arguments can be passed in two ways:
-
Using
args
to pass command arguments. Each argument will be automatically quoted and shell meta-characters will be escaped if needed.cmd
should be an executable name that can be located in thePATH
environment variable, or a full path to an executable. -
When
args
is not given or isnull
, command arguments can be appended tocmd
. No automatic quoting/escaping will be performed.cmd
should be formatted exactly as it would be when typed at the command line. It can run executables, as well as shell commands that are not executables (e.g. on Windows:dir
,cd
,echo
etc).
Use the sys.io.Process
API for more complex tasks, such as background processes, or providing input to the command.
staticcpuTime():Float
Gives the most precise timestamp value available (in seconds), but only accounts for the actual time spent running on the CPU for the current thread/process.
staticexecutablePath():String
Returns the path to the current executable that we are running.
staticexit(code:Int):Void
Exits the current process with the given exit code.
(macro)(eval) Being invoked in a macro or eval context (e.g. with -x
or --run
) immediately terminates
the compilation process, which also prevents the execution of any --next
sections of compilation arguments.
staticgetChar(echo:Bool):Int
Reads a single input character from the standard input and returns it.
Setting echo
to true
will also display the character on the output.
staticgetCwd():String
Gets the current working directory (usually the one in which the program was started).
staticgetEnv(s:String):String
Returns the value of the given environment variable, or null
if it
doesn't exist.
staticprintln(v:Dynamic):Void
Prints any value to the standard output, followed by a newline. On Windows, this function outputs a CRLF newline. LF newlines are printed on all other platforms.
staticprogramPath():String
Returns the absolute path to the current program file that we are running. Concretely, for an executable binary, it returns the path to the binary. For a script (e.g. a PHP file), it returns the path to the script.
staticputEnv(s:String, v:String):Void
Sets the value of the given environment variable.
(java) This functionality is not available on Java; calling this function will throw.
staticsetCwd(s:String):Void
Changes the current working directory.
(java) This functionality is not available on Java; calling this function will throw.
staticsetTimeLocale(loc:String):Bool
Changes the current time locale, which will affect DateTools.format
date formating.
Returns true
if the locale was successfully changed.
staticstderr():Output
Returns the standard error of the process, to which program errors can be written.
staticstdin():Input
Returns the standard input of the process, from which user input can be read.
Usually it will block until the user sends a full input line.
See getChar
for an alternative.
staticstdout():Output
Returns the standard output of the process, to which program output can be written.
staticsystemName():String
Returns the type of the current system. Possible values are:
- "Windows"
- "Linux"
- "BSD"
- "Mac"