这就是我所做的。
我
exec 2>&1在 repoUpdate.sh 文件的顶部添加了,并添加了这段代码以按@DanielMartin的建议读取输出错误,结果是:
public void cmremove(){ try { JSch jsch = new JSch(); Session session = jsch.getSession(user, host, port); UserInfo ui = new SUserInfo(pass, null); session.setUserInfo(ui); session.setPassword(pass); session.connect(); ChannelExec channelExec = (ChannelExec)session.openChannel("exec"); InputStream in = channelExec.getInputStream(); channelExec.setCommand("./repoUpdate.sh"); channelExec.connect(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; int index = 0; while ((line = reader.readLine()) != null) { System.out.println(++index + " : " + line); } int exitStatus = channelExec.getExitStatus(); channelExec.disconnect(); session.disconnect(); if(exitStatus < 0){ System.out.println("Done, but exit status not set!"); } else if(exitStatus > 0){ System.out.println("Done, but with error!"); } else{ System.out.println("Done!"); } } catch(Exception e) { System.err.println("Error: " + e); }}因此,实际上有很大帮助。它确认命令实际上没有按照我的想法正确执行。我在我的java输出中得到了这个:
run:1 : ****Repository update****2 : Location: /home/cissys/repo/3 : Command: svn update /home/cissys/repo/2.3.04 : ./repoUpdate.sh[6]: svn: not found [No such file or directory]Done!BUILD SUCCESSFUL (total time: 2 seconds)
然后,我尝试修改 repoUpdate.sh 文件,为svn命令添加绝对路径(谢谢@ymnk)
exec 2>&1echo ' ****Repository update****'echo ' Location: /home/cissys/repo/'echo -e ' Command: svn update /home/cissys/repo/2.3.0'/opt/subversion/bin/svn update /home/cissys/repo/2.3.0
对于我的Java,我得到了我想要的东西:
run:1 : ****Repository update****2 : Location: /home/cissys/repo/3 : Command: svn update /home/cissys/repo/2.3.04 : At revision 9443.Done!BUILD SUCCESSFUL (total time: 3 seconds)
我发现
$PATH通过java从会话中获取的信息与直接从linux控制台获取的信息不同。因此,添加svn路径实际上可以解决问题。非常感谢您的帮助!



