【发布时间】:2020-09-01 15:51:59
【问题描述】:
我的 Java 项目中有一个带有 vimdiff 命令的 shell 脚本。
操作系统:Windows
在 GitBash 上,当我直接运行 vimdiff 命令时,它可以正常工作并生成结果。
在 GIT BASH 终端上运行良好的命令:
vimdiff file1.log file2.log -c TOhtml -c 'w! result.html' -c 'qa!'
但是,当我尝试在 Java 项目中运行我的测试时,它会卡住一段时间,并且控制台中没有打印任何内容。不知道为什么。
我在 Java 项目中的 shell 脚本 vimDiff.sh
#!/bin/bash
MASTERLOGFILE="$1"
BUILDLOGFILE="$2"
OUTPUTDIFFFILE="$3"
cat $MASTERLOGFILE | cut -d\ -f4- > $MASTERLOGFILE.1
cat $BUILDLOGFILE | cut -d\ -f4- > $BUILDLOGFILE.1
vimdiff $MASTERLOGFILE.1 $BUILDLOGFILE.1 -c TOhtml -c 'w! '"$OUTPUTDIFFFILE"'' -c 'qa!'
调用上述 shell 脚本的我的 Java 测试类:
public class GenerateDiffHtml {
@Test
public void generateSortedLogFiles() throws Exception {
try {
String masterFilePath = "file1.log";
String buildFilePath = "file2.log";
String outputDiffFilePath = "result.html";
String diffScriptPath = "vimDiff.sh";
Process process = null;
String[] cmd = {"sh", diffScriptPath, masterFilePath, buildFilePath, outputDiffFilePath};
process = Runtime.getRuntime().exec(cmd);
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}
运行测试的命令:
mvn clean test -Dtest=GenerateDiffHtml
注意:相同的 Java 代码在 mac 机器上也能正常工作。所以,我想知道这是否与 Windows 上的 Git Bash 永远等待该过程完成有关。
【问题讨论】:
标签: java bash shell process git-bash