File 如何正确复制二进制文件
我使用以下以编程方式构建二进制文件的代码 二进制文件是成功构建的,但现在我想通过代码将其复制到File 如何正确复制二进制文件,file,unix,go,file-permissions,File,Unix,Go,File Permissions,我使用以下以编程方式构建二进制文件的代码 二进制文件是成功构建的,但现在我想通过代码将其复制到go/bin路径,我能够做到,但是它复制了文件,但不是作为可执行文件 有什么不对劲吗源文件是可执行的 bPath := filepath.FromSlash("./integration/testdata/" + fileName) cmd := exec.Command("go", "build", "-o", bPath, ".") cmd.Dir = filepath.FromSlash("../
go/bin
路径,我能够做到,但是它复制了文件,但不是作为可执行文件
有什么不对劲吗源文件是可执行的
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)
副本为:
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
}
问题在于您提供的权限位掩码:
0644
。它不包括可执行权限,这是每个组中的最低位
因此,改用0755
,结果文件将由每个人执行:
err = ioutil.WriteFile(dst, data, 0755)
查看位掩码的含义
相关位掩码表:
# Permission rwx Binary
-------------------------------------------
7 read, write and execute rwx 111
6 read and write rw- 110
5 read and execute r-x 101
4 read only r-- 100
3 write and execute -wx 011
2 write only -w- 010
1 execute only --x 001
0 none --- 000
这是Linux上的吗?用于此task@jcfollower-在linux和mac中都是