exec

package
v12.51.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package exec provides methods for executing commands

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(command string, args ...string) error

Run executes command

Example
err := Run("/bin/echo", "abc", "123")

if err != nil {
	fmt.Printf("Error: %v", err)
}
Output:

func RunAsUser

func RunAsUser(user, logFile, command string, args ...string) error

RunAsUser runs command as a given user

Example
// run echo as user some user and redirect output to /var/log/output.log
err := RunAsUser("someuser", "/var/log/output.log", "/bin/echo", "abc", "123")

if err != nil {
	fmt.Printf("Error: %v", err)
}
Output:

func Sudo

func Sudo(user string, args ...string) error

Sudo executes command with sudo

Example
err := Sudo("/bin/echo", "abc", "123")

if err != nil {
	fmt.Printf("Error: %v", err)
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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