2015-06-30 79 views
0

我试图用问题与运行git从java程序的命令

Runtime.getRuntime().exec(commandToBeExecuted); 

and commandToBeExecuted ="git log" ; 

我已经设置ENV变量运行通过java程序一个git命令,但仍然得到错误,如:

java.io.IOException: Cannot run program "git": CreateProcess error=2, The system cannot find the file specified 
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) 
    at java.lang.Runtime.exec(Runtime.java:615) 
    at java.lang.Runtime.exec(Runtime.java:448) 
    at java.lang.Runtime.exec(Runtime.java:345) 
    at GITCodeCoverage.createLog(GITCodeCoverage.java:40) 
    at GITCodeCoverage.main(GITCodeCoverage.java:17) 
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified 
    at java.lang.ProcessImpl.create(Native Method) 
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:188) 
    at java.lang.ProcessImpl.start(ProcessImpl.java:132) 
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021) 
    ... 5 more 

任何这个命令可以帮助我在Windows系统上成功运行这个命令。

在此先感谢!

+0

只要你知道,没有安装我的Ubuntu机器使用Git上会出现此错误。 –

+0

这个错误不会发生在我的Windows机器上。当你在cmd中手动输入时,做这个命令的工作是什么? –

+0

是的,当我从命令Promt运行此命令它工作正常,并给出结果。我是否需要在日食中设置任何路径。 –

回答

0

尝试使用此重载Runtime.exec(String command, String[] envp, File dir),如: -

File gitPath = new File("path where git is located in your system"); 
Runtime.exec('git logs', null, gitPath); 
+0

我尝试使用文件gitPath =新文件(“C:/ Program Files(x86)/ Git/bin /”);进程p = Runtime.getRuntime()。exec(“git log”,null,gitPath);但仍然geting的错误信息:java.io.IOException:无法运行程序“git”(在目录“C:\ Program Files文件(x86)\ Git \ bin”):CreateProcess错误= 2,系统找不到指定的文件 –

+0

你能从命令提示符窗口运行'git log'吗?并检查该git是否存在于该位置 –

+0

我已经运行了那个通过cmd,并给我的输出,但我调查,发现有需要在Eclipse中设置run-config下git的路径,谢谢你这么多为你提供帮助。 –