[英]Shell script with vimdiff command in Java source code gets stuck when run on Git bash
我的 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!'
我的Java测试Class就是调用上面的shell脚本:
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 机器上工作正常。 所以,我想知道这是否与 Git Bash on Windows 永远等待进程完成有关。
由于您使用 GitBash 在 Windows 中运行 shell 脚本。 VimDiff 基本上是一个需要用户操作的 VI 编辑器。 由于您在后台执行脚本,因此任何人都无法执行任何操作。
因此,请通过以下方式尝试一下
process.waitFor();
来自您的 java 代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.