[英]Shell script with vimdiff command in Java source code gets stuck when run on Git bash
I have a shell script with vimdiff command in my Java project.我的 Java 项目中有一个带有 vimdiff 命令的 shell 脚本。
OS: Windows操作系统:Windows
On GitBash, when I run the vimdiff command directly, it works fine and generates the result.在 GitBash 上,当我直接运行 vimdiff 命令时,它工作正常并生成结果。
Command that works fine on GIT BASH terminal:在 GIT BASH 终端上运行良好的命令:
vimdiff file1.log file2.log -c TOhtml -c 'w! result.html' -c 'qa!'
But, when I try to run my test in the Java project, it gets stuck for a while and nothing is printed in the console.但是,当我尝试在 Java 项目中运行我的测试时,它卡住了一段时间,控制台中没有打印任何内容。 Not sure why.
不知道为什么。
My shell script vimDiff.sh within the Java project我的 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!'
My Java Test Class that calls the above shell script:我的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();
}
}
}
Command to run the test:运行测试的命令:
mvn clean test -Dtest=GenerateDiffHtml
Note: The same Java code works fine on a mac machine.注意:相同的 Java 代码在 mac 机器上工作正常。 So, I wonder if this has something to do with Git Bash on Windows waiting forever, for the process to complete.
所以,我想知道这是否与 Git Bash on Windows 永远等待进程完成有关。
Since you are running shell scripts in Windows using GitBash.由于您使用 GitBash 在 Windows 中运行 shell 脚本。 VimDiff is basically a VI editor which requires an action from user.
VimDiff 基本上是一个需要用户操作的 VI 编辑器。 Since you are executing script in background there is no way to perform any action by anyone.
由于您在后台执行脚本,因此任何人都无法执行任何操作。
Hence, kindly give it a try by following因此,请通过以下方式尝试一下
process.waitFor();
process.waitFor();
from your java code.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.