[英]issue with running git commands from java program
我正在尝试使用以下方法通过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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.