package executil
import "github.com/tredoe/osutil/executil"
Package executil lets to call to system commands.
Index ¶
- Variables
- func CloseBootLogger() error
- func Exec(cmd string, args ...string) (stdout, stderr []byte, err error)
- func ExecAsBash(command string) (output []byte, err error)
- func ExecAsBashWithMatch(command string) (output []byte, match bool, err error)
- func ExecAsBashWithMatchf(format string, args ...interface{}) ([]byte, bool, error)
- func ExecAsBashf(format string, args ...interface{}) ([]byte, error)
- func ExecNoStdErr(extraEnv []string, cmd string, args ...string) error
- func ExecToStd(extraEnv []string, cmd string, args ...string) error
- func ExecToStdButErr(checkStderr []byte, extraEnv []string, cmd string, args ...string) error
- func ExecWinshell(sh WinShell, closeWindow bool, cmd string) (out []byte, err error)
- func ExecWithTime(timeKillCmd time.Duration, cmd string, args ...string, ) (stdout, stderr []byte, err error)
- func SaveCmdOut(dir, filename string, stdout, stderr []byte, fnCheckStderr func([]byte) error, ) (err error)
- func StartBootLogger()
- type WinShell
Variables ¶
var DebugAsBash bool
DebugExecAsBash shows debug messages at functions related to 'ExecAsBash()'.
ErrProcKilled reports an error by a process killed.
var ListWinShell = []WinShell{ Cmd, Db2, }
ListWinShell is the list of Windows shells.
Functions ¶
func CloseBootLogger ¶
func CloseBootLogger() error
CloseBootLogger closes the log file.
func Exec ¶
Exec executes a command. Returns both standard output and error.
func ExecAsBash ¶
ExecAsBash executes external commands just like ExecAsBashWithMatch, but does not return the boolean `match`.
func ExecAsBashWithMatch ¶
ExecAsBashWithMatch executes external commands with access to shell features such as filename wildcards, shell pipes, environment variables, and expansion of the shortcut character "~" to home directory. It also logs the command.
This function avoids to have execute commands through a shell since an unsanitized input from an untrusted source makes a program vulnerable to shell injection, a serious security flaw which can result in arbitrary command execution.
The most of commands return a text in output or an error if any. `match` is used in commands like *grep*, *find*, or *cmp* to indicate if the search is matched.
func ExecAsBashWithMatchf ¶
ExecAsBashWithMatchf is like ExecAsBashWithMatch, but formats its arguments according to the format. Analogous to Printf().
func ExecAsBashf ¶
ExecAsBashf is like ExecAsBash, but formats its arguments according to the format. Analogous to Printf().
func ExecNoStdErr ¶
ExecNoStdErr executes a command setting only standard output. Logs the command.
func ExecToStd ¶
ExecToStd executes a command setting both standard output and error. Logs the command.
func ExecToStdButErr ¶
ExecToStdButErr executes a command setting the standard output. Logs the command.
checkStderr (if any) checks if it is found in the standard error to know whether the standard error is not really an error.
func ExecWinshell ¶
ExecWinshell executes a command into a Windows' shell called from Powershell. Logs the command and returns the command output.
func ExecWithTime ¶
func ExecWithTime(timeKillCmd time.Duration, cmd string, args ...string, ) (stdout, stderr []byte, err error)
ExecWithTime executes a command waiting to finish the command before of kill it ('timeKillCmd'), or waits without kill it when the duration is lesser or equal to zero). Logs the command and returns both standard output and error.
func SaveCmdOut ¶
func SaveCmdOut(dir, filename string, stdout, stderr []byte, fnCheckStderr func([]byte) error, ) (err error)
SaveCmdOut saves both standard out and error to files, and print the standard out (if any). fnCheckStderr is a function to check the standard error.
func StartBootLogger ¶
func StartBootLogger()
StartBootLogger initializes the log file to be used during the boot.
Types ¶
type WinShell ¶
type WinShell uint8
WinShell represents a Windows shell.
const ( Cmd WinShell Db2 )
Windows shells.
func (WinShell) String ¶
Source Files ¶
bash.go doc.go env.go errors.go exec.go log.go win.go
- Version
- v1.1.1
- Published
- Aug 1, 2021
- Platform
- js/wasm
- Imports
- 13 packages
- Last checked
- 1 day ago –
Tools for package owners.