问题与使用Java程序的git blame命令 [英] issue with git blame command using java program

查看:167
本文介绍了问题与使用Java程序的git blame命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  git --git-dir D:\\ \\ code_coverage \.git blame'src / RunCodeCoverage.java'
| grep e4ecfbe | awk'{print $ 7}'

它给了我错误:

  fatal:can stat path'$ 7}'':没有这样的文件或目录

从命令提示符运行此命令时,它会根据需要提供结果。



请帮忙!

$ b $在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中使用该命令:
$ b

  String commandToBeExecuted = git --git-dir D:\ code_coverage \.git blame'src / RunCodeCoverage.java'| grep e4ecfbe | awk{print $ 7}'; 
进程p = Runtime.getRuntime()。exec(commandToBeExecuted);

但是您绝不会将所有参数作为单个字符串传递。

使用数组,如在getRuntime().exe中使用引号如何使管道与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} \


I am trying to run below git command using java program on windows.

 git --git-dir D:\code_coverage\.git blame  'src/RunCodeCoverage.java'
 | grep e4ecfbe | awk '{print $7}'

it gives me error :

fatal: cannot stat path '$7}'': No such file or directory

While running this command from command prompt, it gives me results as desired.

Please help!

解决方案

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}\""

这篇关于问题与使用Java程序的git blame命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆