I use the following code which build binary programmatically
the binary is build successfully but now I want to copy it via code to go/bin
path, and I was able to do it, but it copy the file but not as executable.
what could be wrong ? the source file is executable
bPath := filepath.FromSlash("./integration/testdata/" + fileName)
cmd := exec.Command("go", "build", "-o", bPath, ".")
cmd.Dir = filepath.FromSlash("../")
err := cmd.Run()
if err != nil {
fmt.Println("binary creation failed: ", err)
}
fmt.Println(os.Getenv("GOPATH"))
dir, _ := os.Getwd()
srcPath := filepath.Join(dir, "testdata", , fileName)
targetPath := filepath.Join(os.Getenv("GOPATH"),"/bin/",fileName)
copy(srcPath, targetPath)
The copy is:
func copy(src string, dst string) error {
// Read all content of src to data
data, err := ioutil.ReadFile(src)
if err != nil {
return err
}
// Write data to dst
err = ioutil.WriteFile(dst, data, 0644)
if err != nil {
return err
}
return nil
}