Golang Run Command Line

package main

import (

func main() {
app := "date"

arg0 := "-d"
arg1 := "3 Jan 2009 12:34:56 AM"
arg2 := "+%Y-%m-%d %H:%M:%S"

cmd := exec.Command(app, arg0, arg1, arg2)
stdout, err := cmd.Output()

if err != nil {

func Bash(cmd string) string{
strUUID := uuid.New().String()
strPath := fmt.Sprintf("/tmp/%s.sh", strUUID)
ioutil.WriteFile(strPath, []byte(cmd), 0744)
out,err := exec.Command("/bin/bash", strPath).CombinedOutput()
return string(out[:])



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin FOO

Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.