【问题标题】:How to solve the error of the rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.2]如何解决rsync错误的错误:pipe.c(85) [sender=3.1.2]的IPC代码(代码14)错误
【发布时间】: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) 现在你能解决我的问题吗?

标签: ubuntu go rsync mkdir


【解决方案1】:

您需要删除 -e 选项,因为这将使用以下工作 (--rsync-path=...) 作为 ssh 命令的替换。例如,

$ rsync -ave --x_x  /tmp/a abc@localhost:/tmp/y
rsync: Failed to exec --x_x: No such file or directory (2)

只需使用-av

【讨论】:

  • 正如你所说@meuh 我删除了标志-e 然后我运行命令然后它会给我错误exit status 1: rsync version 3.1.2 protocol version 31 Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
  • exit 1 是参数中的语法错误。也许您的 pathfilePath 字符串包含由 shell 解释的字符。尝试在 ExecuteCommand (cmd := exec.Command("sh", "-xc",command)) 中添加 -x 以查看实际传递给 rsync 的内容。
  • 现在它会打印这个exit status 1: + rsync rsync version 3.1.2 protocol version 31
  • 我不懂 go 语言,所以我无法为您提供帮助。您没有收到完整的错误消息。也许您在将-ave 转换为-av 时引入了输入错误。
  • 你能告诉我如何在 ubuntu 终端上成功运行这个命令吗? @meuh