On a CMD in Windows, I can make it work using double quotes for the awk
parameters:
git --git-dir D:\code_coverage\.git blame 'src/RunCodeCoverage.java'
| grep e4ecfbe | awk "{print $7}"
Note that my awk.exe
comes from Gnu On Windows.
The OP mentions using that command in Java with:
String commandToBeExecuted="git --git-dir D:\code_coverage\.git blame 'src/RunCodeCoverage.java' | grep e4ecfbe | awk "{print $7}"'";
Process p = Runtime.getRuntime().exec(commandToBeExecuted);
But you never pass all parameters as a single string.
Use an array, as in "Using Quotes within getRuntime().exec" and in "How to make pipes work with Runtime.exec()?"
Process p = Runtime.getRuntime().exec(new String[]{"cmd", "/c", commandToBeExecuted);
Escape the double quotes in commandToBeExecuted
:
commandToBeExecuted = "git --git-dir D:\code_coverage\.git blame 'src/RunCodeCoverage.java'
| grep e4ecfbe | awk \"{print $7}\""