Skip to content

Instantly share code, notes, and snippets.

@junxie6
Last active April 21, 2020 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junxie6/329bfbed7d513d159fdc68fe1c05837e to your computer and use it in GitHub Desktop.
Save junxie6/329bfbed7d513d159fdc68fe1c05837e to your computer and use it in GitHub Desktop.
run external command
package main
import (
"fmt"
"os"
"os/exec"
"path"
)
func main() {
dumpDir := `C:\Dev\Go\test`
args := []string{"-u", "root", "-p", "-P", "3306", "dbname"}
out, err := os.OpenFile(path.Join(dumpDir, "dump.sql"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
fmt.Printf("%v", err)
}
cmd := exec.Command(`C:\Program Files (x86)\winsim\ConnectionManager\MySqlBinary\5.6.10\mysql\mysqldump.exe`, args...)
cmd.Stdout = out
if err := cmd.Run(); err != nil {
fmt.Printf("%v", err)
}
//if cmdOut, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil {
// fmt.Printf("%v", err)
//}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment