【发布时间】:2025-12-10 21:35:02
【问题描述】:
我正在使用 rsync 命令创建一个新目录来保存图像,命令是"rsync -ave --rsync-path='mkdir -p " + path + " && rsync' " + filePath + " ubuntu@" + LocalhostIp + ":" + path,但是在运行我的代码时,这个命令会给我错误,错误是
错误:
退出状态14:rsync:执行失败--rsync-path=mkdir:没有这样的文件或目录(2)
rsync 错误:pipe.c(85) [sender=3.1.2] 处的 IPC 代码(代码 14)出错
rsync:连接意外关闭(到目前为止收到 0 个字节)[发送者]
rsync 错误:io.c(235) [sender=3.1.2] 处的 IPC 代码(代码 14)错误
编辑
func CopyUploadedFileToAppServers(filePath, path string) {
ExecuteCommand("rsync -ave --rsync-path='mkdir -p " + path + " && rsync' " + filePath + " ubuntu@" + LocalhostIp + ":" + path)
}
func ExecuteCommand(command string) error{
cmd := exec.Command("sh", "-c",command)
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return err
}
fmt.Println("Result: " + out.String())
return nil
}
我该如何解决这个错误?
【问题讨论】:
-
在 ExecuteCommand func 中将
cmd := exec.Command("sh", "-c",command)替换为cm := []string{"-c"} cm = append(cm, strings.Split(command, " ")...) cmd := exec.Command("sh", cm...) -
@hoque 你告诉我的解决方案我将它应用到我的代码中并运行但它给了我
exit status 1: rsync version 3.1.2 protocol version 31 Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/的错误 -
你能确保你的
rsync -ave --rsync-path='mkdir -p " + path + " && rsync' " + filePath + " ubuntu@" + LocalhostIp + ":" + path命令在你的电脑上工作吗?如果你给出变量的值,对我来说也很容易,这样我就可以检查了。 -
@hoque 我直接在终端运行这个
rsync -ave --rsync-path="mkdir -p /var/www/html/uploads/ironnetwork/ && rsync" /var/www/html/uploads/ironnetwork/1542607804image.命令,它会给我错误sending incremental file list rsync: change_dir "/var/www/html/uploads/ironnetwork" failed: No such file or directory (2)现在你能解决我的问题吗?