我正在尝试使用
通过java程序运行git命令Runtime.getRuntime().exec(commandToBeExecuted);
and commandToBeExecuted ="git log" ;
我设置了env变量,但仍然得到如下错误:
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 :(得分: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);