gpt4 book ai didi

java - 从 java 程序运行 "rsync"的 link_stat 错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:46:14 26 4
gpt4 key购买 nike

我想从 java 程序运行 rsync。这是代码:

        String cmd = "rsync -auv /rsrch1/rists/moonshot/data/foundation/FoundationMedicine/*.csv " + archive.getAbsolutePath();
System.out.println(cmd);

// capture stdout and stderr from running bash script
Process p = Runtime.getRuntime().exec(cmd);
String line;
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = in.readLine()) != null) {
System.out.println(line);
}
BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = err.readLine()) != null) {
System.out.println(line);
}
p.waitFor();
in.close();
err.close();

然而,当我运行这个 java 程序时,我得到了错误:

rsync -auv /rsrch1/rists/moonshot/data/foundation/FoundationMedicine/*.csv /rsrch1/rists/moonshot/data/dev/foundation/validation/archive
sending incremental file list

sent 18 bytes received 12 bytes 60.00 bytes/sec
total size is 0 speedup is 0.00
rsync: link_stat "/rsrch1/rists/moonshot/data/foundation/FoundationMedicine/*.csv" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

当我运行那个确切的命令时> 尽管直接在服务器上,它工作得很好。

我不明白为什么它不适用于 Java。

最佳答案

经过一番研究,我发现这是由命令中的“*”引起的。这是一个只能被 bash 识别的通配符,我必须用 bash 运行这个命令。得到它与以下工作:

String[] cmd = new String[]{"/bin/bash", "rsync -auv /rsrch1/rists/moonshot/data/foundation/FoundationMedicine/*.csv " + archive.getAbsolutePath()};

关于java - 从 java 程序运行 "rsync"的 link_stat 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36846438/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com