我正在尝试运行下面的git命令使用java程序在windows上。
git --git-dir D:\code_coverage\.git blame 'src/RunCodeCoverage.java'
| grep e4ecfbe | awk '{print $7}'它会给我一个错误:
fatal: cannot stat path '$7}'': No such file or directory当从命令提示符运行此命令时,它会给出所需的结果。
请帮帮我!
发布于 2015-07-03 13:36:18
在Windows中的CMD上,我可以对awk参数使用双引号使其工作:
git --git-dir D:\code_coverage\.git blame 'src/RunCodeCoverage.java'
| grep e4ecfbe | awk "{print $7}"请注意,我的awk.exe来自Gnu On Windows。
这个OP提到在Java中使用该命令:
String commandToBeExecuted="git --git-dir D:\code_coverage\.git blame 'src/RunCodeCoverage.java' | grep e4ecfbe | awk "{print $7}"'";
Process p = Runtime.getRuntime().exec(commandToBeExecuted);但是您永远不会将所有参数作为一个字符串进行传递。
使用数组,例如在"Using Quotes within getRuntime().exec“和"How to make pipes work with Runtime.exec()?”中
Process p = Runtime.getRuntime().exec(new String[]{"cmd", "/c", commandToBeExecuted);转义commandToBeExecuted中的双引号
commandToBeExecuted = "git --git-dir D:\code_coverage\.git blame 'src/RunCodeCoverage.java'
| grep e4ecfbe | awk \"{print $7}\""https://stackoverflow.com/questions/31199139
复制相似问题