我正在为我的CSVreader创建一个Junit测试文件.我正在阅读CSV文件的内容并将内容写入另一个文件.我想使用diff实用程序比较它们,我想使用diff的退出状态来知道内容是否相同.一般是$?给出退出状态,但我不知道如何捕获它并在我的代码中使用它.谁可以在这方面帮助我?
这就是我的代码看起来的样子
- boolean hasSameContents = false;
- command="diff "+mp.get("directory")+"/"+fileName+" "+mp.get("outdir")+"/"+fileName;
- p= Runtime.getRuntime().exec(command);
- p.waitFor();
在此之后我想获得退出状态并在if这样的条件下使用它
- if(exit_status==0)
- hasSameContents = true;
- else
- hasSameContents = false;
甚至其他建议也很受欢:)
解决方法
你在找
Process#exitValue
- String command = "diff "+mp.get("directory")+"/"+fileName+" "+mp.get("outdir")+"/"+fileName;
- Process p = Runtime.getRuntime().exec(command);
- p.waitFor();
- int exitStatus = p.exitValue();