# System Package system contains some functions about os, runtime, shell command.
## Source: - [https://github.com/duke-git/lancet/blob/main/system/os.go](https://github.com/duke-git/lancet/blob/main/system/os.go) ## Usage: ```go import ( "github.com/duke-git/lancet/v2/system" ) ``` ## Index - [IsWindows](#IsWindows) - [IsLinux](#IsLinux) - [IsMac](#IsMac) - [GetOsEnv](#GetOsEnv) - [SetOsEnv](#SetOsEnv) - [RemoveOsEnv](#RemoveOsEnv) - [CompareOsEnv](#CompareOsEnv) - [ExecCommand](#ExecCommand) ## Documentation ### IsWindowsCheck if current os is windows.
Signature: ```go func IsWindows() bool ``` Example: ```go import ( "fmt" "github.com/duke-git/lancet/v2/system" ) func main() { isOsWindows := system.IsWindows() fmt.Println(isOsWindows) } ``` ### IsLinuxCheck if current os is linux.
Signature: ```go func IsLinux() bool ``` Example: ```go import ( "fmt" "github.com/duke-git/lancet/v2/system" ) func main() { isOsLinux := system.IsLinux() fmt.Println(isOsLinux) } ``` ### IsMacCheck if current os is macos.
Signature: ```go func IsMac() bool ``` Example: ```go import ( "fmt" "github.com/duke-git/lancet/v2/system" ) func main() { isOsMac := system.IsMac fmt.Println(isOsMac) } ``` ### GetOsEnvGets the value of the environment variable named by the key.
Signature: ```go func GetOsEnv(key string) string ``` Example: ```go import ( "fmt" "github.com/duke-git/lancet/v2/system" ) func main() { fooEnv := system.GetOsEnv("foo") fmt.Println(fooEnv) } ``` ### SetOsEnvSets the value of the environment variable named by the key.
Signature: ```go func SetOsEnv(key, value string) error ``` Example: ```go import ( "fmt" "github.com/duke-git/lancet/v2/system" ) func main() { err := system.SetOsEnv("foo", "foo_value") fmt.Println(err) } ``` ### RemoveOsEnvRemove a single environment variable.
Signature: ```go func RemoveOsEnv(key string) error ``` Example: ```go import ( "fmt" "github.com/duke-git/lancet/v2/system" ) func main() { err := system.RemoveOsEnv("foo") if err != nil { fmt.Println(err) } } ``` ### CompareOsEnvGet env named by the key and compare it with comparedEnv.
Signature: ```go func CompareOsEnv(key, comparedEnv string) bool ``` Example: ```go import ( "fmt" "github.com/duke-git/lancet/v2/system" ) func main() { system.SetOsEnv("foo", "foo_value") res := system.CompareOsEnv("foo", "foo_value") fmt.Println(res) //true } ``` ### CompareOsEnvuse shell /bin/bash -c(linux) or cmd (windows) to execute command.
Signature: ```go func ExecCommand(command string) (stdout, stderr string, err error) ``` Example: ```go import ( "fmt" "github.com/duke-git/lancet/v2/system" ) func main() { out, errout, err := system.ExecCommand("ls") fmt.Println(out) fmt.Println(errout) fmt.Println(err) } ```