首页 > 解决方案 > ProcessBuilder:Git 存储库不下载

问题描述

我正在使用 ProcessBuilder 从 Git 下载。这是我当前的代码:

Process process = null;
try {
    String[] command = {"git", "clone", gitLink};
    ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.directory(new File(gitPath));
    process = processBuilder.start();

    System.out.println("\n*** Console output is:");
    InputStream processStdOutput = process.getInputStream();
    Reader r = new InputStreamReader(processStdOutput);
    BufferedReader br = new BufferedReader(r);
    String line;
    while ((line = br.readLine()) != null) { System.out.println("\t" + line); }

    process.getOutputStream().close();
} catch (IOException e) { e.printStackTrace(); }
finally { if (process != null) { process.destroy(); } }

因此,gitLink这将是我要下载的存储库的实际链接,并且gitPath是在我的 PC 上下载到的位置。gitPath似乎有效,因为我通过执行 command 对其进行了测试lsgitLink,但是,什么也没显示。我得到了 Git 存储库一秒钟(在正确的gitPath文件夹中),然后它就消失了。此外,当我使用 Git 存储库的实际链接而不是变量gitLink时,它可以完美运行。出于某种原因,它不喜欢变量 gitLink。

这是有效的代码:

String[] command = {"git", "clone", "https://some-rep.git"};

其他的事情是平等的。

标签: javagitgithub

解决方案


推荐阅读