shell

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

Shell

run powershell and bash with go.

Run powershell and bash

import "github.com/abdfnx/shell"

shell.Run("git status")

// run a command with output
err, out, errout := shell.RunOut("whoami")

if err != nil {
  log.Printf("error: %v\n", err)
  fmt.Print(errout)
}

fmt.Print(out)

Powershell

import "github.com/abdfnx/shell"

// run a command
shell.PWSLCmd(`Write-Host "secman is 🔒"`)

// run a script
shell.PWSLCmd(`
  $x = git config user.name
  
  Write-Host $x
`)

// run a command with output
err, out, errout := shell.PWSLOut(`[System.Environment]::SetEnvironmentVariable("Path", $Env:Path + ";$SECMAN_PATH\bin", [System.EnvironmentVariableTarget]::User)`)

if err != nil {
  log.Printf("error: %v\n", err)
  fmt.Print(errout)
}

fmt.Print(out)

Bash/Shell

import "github.com/abdfnx/shell"

// run a command
shell.ShellCmd(`echo "secman is 🔒"`)

// run a script
shell.ShellCmd(`
  mood="👨‍💻"

  if [ $mood != "😪" ]; then
    echo "still coding"
  fi
`)

// run a command with output
err, out, errout := shell.ShellOut(`curl --silent "https://api.github.com/repos/scmn-dev/secman/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`)

if err != nil {
  log.Printf("error: %v\n", err)
  fmt.Print(errout)
}

fmt.Print(out)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PWSLCmd

func PWSLCmd(command string)

func PWSLOut

func PWSLOut(command string) (error, string, string)

func Run

func Run(cmd string)

func RunOut

func RunOut(unixCmd string, winCmd string) (error, string, string)

func ShellCmd

func ShellCmd(command string)

func ShellOut

func ShellOut(command string) (error, string, string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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