Last active
April 21, 2020 19:29
-
-
Save junxie6/329bfbed7d513d159fdc68fe1c05837e to your computer and use it in GitHub Desktop.
run external command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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