我正在尝试使用
通过 java 程序运行 git 命令Runtime.getRuntime().exec(commandToBeExecuted);
and commandToBeExecuted ="git log" ;
我已经设置了环境变量,但仍然收到如下错误:
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 系统上成功运行此命令。
提前致谢!
最佳答案
尝试使用这个重载的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);
关于java - 从java程序运行git命令的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31137735/