Documentation ¶
Index ¶
- func Pipe(dir string, args ...[]string)
- func PipeMultiDir(args ...[]string)
- func PipeMultiDirEnv(env []string, args ...[]string)
- func Run(args []string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
- func RunRaw(cmdStr string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
- func RunUser(cmdStr string, user string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
- func RunUserFile(file string, args []string, user string, dir string, env []string, ...) (output []byte, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Pipe ¶
Pipe allows you to pipe multiple bash commands
[example (bash)]
echo "test" | tee -a "./test.txt"
[example (go)]
bash.Pipe(".", []string{"echo", "test"}, []string{"tee", "-a", "./test.txt"}) @dir: a directory to run the command in (set to an empty string to disable)
func PipeMultiDir ¶
func PipeMultiDir(args ...[]string)
PipeMultiDir allows you to pipe multiple bash commands with a different directory for each of them
note: the first arg is the directory
[example]
bash.PipeMultiDir([]string{"/dir1", "cat", "test.txt"}, []string{"./dir2", "tee", "-a", "./test.txt"})
func PipeMultiDirEnv ¶
PipeMultiDirEnv is just like the 'PipeMultiDir' method, but it also allows you to add custom envirronment vars
note: the first arg is the directory
[example]
bash.PipeMultiDirEnv([]string{`MyEnvVar=CustomValue`}, []string{"/dir1", "cat", "test.txt"}, []string{"./dir2", "tee", "-a", "./test.txt"})
func Run ¶
Run will run a bash command based on the given args
note: stdin is piped to the os logs
@dir: a directory to run the command in (set to an empty string to disable) @env: an optional list of environment variables (set to nil to disable)
[optional]
@liveOutput[0]: set to true to pipe stdout and stderr to the os @liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden
func RunRaw ¶
RunRaw will run an unescaped (unquoted) bash command as a different user
this method uses `bash -c` to get around the auto quotes added by golang
note: user input is Not recommended for this method
note: stdin is piped to the os logs
@cmdStr: the command to run @dir: a directory to run the command in (set to an empty string to disable) @env: an optional list of environment variables (set to nil to disable)
[optional]
@liveOutput[0]: set to true to pipe stdout and stderr to the os @liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden
func RunUser ¶
func RunUser(cmdStr string, user string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
RunUser will run an unescaped (unquoted) bash command as a specified user
this method uses `runuser -l [user] -c`
note: user input is Not recommended for this method
note: stdin is piped to the os logs
@cmdStr: the command to run @user: the username to run the command as @dir: a directory to run the command in (set to an empty string to disable) @env: an optional list of environment variables (set to nil to disable)
[optional]
@liveOutput[0]: set to true to pipe stdout and stderr to the os @liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden
func RunUserFile ¶
func RunUserFile(file string, args []string, user string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
RunUserFile will run a bash file as a specified user
this method uses `pkexec --user [user]` to simulate a user in a normal desktop environment
note: user input is Not recommended for this method
note: stdin is piped to the os logs
@file: the file to run @user: the username to run the command as @dir: a directory to run the command in (set to an empty string to disable) @env: an optional list of environment variables (set to nil to disable)
[optional]
@liveOutput[0]: set to true to pipe stdout and stderr to the os @liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden
Types ¶
This section is empty.