osutils

package module
v0.0.0-...-24f34be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2020 License: MIT Imports: 16 Imported by: 1

README

osutils

GO utility functions for OS access

Documentation

Index

Constants

View Source
const (
	MCL_CURRENT = 1 /* lock all current mappings */
	MCL_FUTURE  = 2 /* lock all future mappings */
	MCL_ONFAULT = 4 /* lock all pages that are faulted in */
)

Variables

This section is empty.

Functions

func CustomSplit

func CustomSplit(line string, sep string, skipAdjacent bool) (words []string, err error)

CustomSplit splits the given string into individual words using the separator runes. Quotes and escapes are handled correctly and will be preserved. If a quote is not closed properly, an error is returned.

func CustomSplitN

func CustomSplitN(line string, sep string, skipAdjacent bool, n int) (words []string, err error)

CustomSplitN splits the given string into max. n individual words using the separator runes. Quotes and escapes are handled correctly and will be preserved. If a quote is not closed properly, an error is returned.

func DisableOOMKiller

func DisableOOMKiller() error

func GetExecutable

func GetExecutable() string

func LockMemory

func LockMemory() error

func SetProcessPriority

func SetProcessPriority(prio int) error

func ShellEscape

func ShellEscape(text string) string

ShellEscape escapes the given string for use as an argument in the shell.

func ShellEscapeAll

func ShellEscapeAll(list []string) (result []string)

ShellEscapeAll escapes the given string slice using ShellEscape.

func ShellSplit

func ShellSplit(line string) (words []string, err error)

ShellSplit splits the given string into individual words just like a shell does while paying attention to quotes and escapes. If quote is not closed properly, an error is returned.

func ShellSplitN

func ShellSplitN(line string, n int) (words []string, err error)

ShellSplit splits the given string into individual words just like a shell does while paying attention to quotes and escapes. If quote is not closed properly, an error is returned.

func ShellUnescape

func ShellUnescape(text string) (result string, err error)

ShellUnescape...

func ShellWords

func ShellWords(line string) (words []string, err error)

ShellWords splits the given string using ShellSplit and unescapes the resulting words. If an error occurs during parsing (e.g., open quotes), parsing will continue and the first error returned.

Types

type AppInfo

type AppInfo struct {
	Executable string
	Folder     string
	Name       string

	Description string
	Version     string
}

func EnsureAppInfo

func EnsureAppInfo() *AppInfo

func GetAppInfo

func GetAppInfo() (*AppInfo, error)

type Command

type Command struct {
	// Path is the path of the command to run.
	Path string

	// Args holds command line arguments.
	Args []string

	// Env specifies the environment of the process.
	// If Env is nil, Run uses the current process's environment.
	Env []string

	// Dir specifies the working directory of the command.
	Dir string

	// Stdin
	Stdin io.Reader

	// Stdout
	Stdout io.Writer

	// Stderr
	Stderr io.Writer

	// Timeout
	Timeout time.Duration
}

func NewCommand

func NewCommand(name string, arg ...string) *Command

NewCommand returns the Command struct to execute the named program with the given arguments.

func (*Command) Exec

func (c *Command) Exec() (ExecResult, error)

Exec runs the command and returns a struct containing the result or an error if the command could not be executed.

type ExecResult

type ExecResult struct {
	ExitStatus int
	Stdout     string
	Stderr     string
}

func Exec

func Exec(cmd string, args ...string) (result ExecResult, err error)

Exec runs the given command with arguments and returns the resulting exit status, stdout and stderr. An error will only be returned if the execution itself fails, not if the command exitted with a non-zero exit status.

func ExecWithEnv

func ExecWithEnv(env []string, cmd string, args ...string) (result ExecResult, err error)

Exec runs the given command with arguments and environment and returns the resulting exit status, stdout and stderr. An error will only be returned if the execution itself fails, not if the command exitted with a non-zero exit status.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL