我试图通过Java中的进程命令访问SVN,作为更大的GUI的一部分来查看SVN上的文件。经过大量研究,我大大改善了我的方法,但是我仍然无法完成。如果我在GUI中运行代码,它只会挂起。为了发现问题所在,我将其简化并作为控制台程序运行。当我在那里运行它时,它显示了对我的GNOME密钥环的请求。我的代码输入密码,但控制台似乎不接受它。我的代码如下:向Java进程发送密码
public class SvnJavaTest{
public static void main(String[] args){
try {
String[] commands = {"svn", "ls", "https://svnserver"};
Process beginProcess = Runtime.getRuntime().exec(commands, null, new File("/home/users/ckorb/Desktop"));
BufferedReader br = new BufferedReader(new InputStreamReader(beginProcess.getInputStream()));
BufferedWriter write = new BufferedWriter(new OutputStreamWriter(beginProcess.getOutputStream()));
write.write("password");
write.flush();
String line=br.readLine();
while (line != null){
System.out.println(line);
line =br.readLine();
}
br.close();
write.close();
beginProcess.waitFor();
} catch (IOException e1) {
e1.printStackTrace();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}
我没有得到这个运行任何错误,如果我在密码手动输入到控制台,然后运行它,它的作品,因为它会记住我的密码。我看过并发现有一些软件包会在登录时自动进入我的钥匙圈,但这不是真正的选择。非常感谢你。
非常感谢。 –