issue with running git commands from java program - java

I am trying to run a git command through java program using
Runtime.getRuntime().exec(commandToBeExecuted);
and commandToBeExecuted ="git log" ;
i have set env variables but still getting the error like:
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
Any can please help me in this run this command succesfully on Windows system.
Thanks in advance!

Try using this overloaded Runtime.exec(String command, String[] envp, File dir) like:-
File gitPath = new File("path where git is located in your system");
Runtime.exec('git logs', null, gitPath);

Related

Can't read data file: '\espeak-data\phontab' error while trying to use harium eSpeak in Java

I'm trying to read out a text by using eSpeak text to speech. I tried so by installing eSpeak and adding the harium wrapper to my project:
import com.harium.hci.espeak.Espeak;
public class Main {
public static void main(String[] args) {
Espeak espeak = new Espeak();
espeak.speak("Hello World!");
}
}
However, as soon as I ran the code I got this error message:
java.io.IOException: Cannot run program "espeak": CreateProcess error=2, The system cannot find the file specified
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
at com.harium.hci.espeak.Espeak$1.run(Espeak.java:60)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.base/java.lang.ProcessImpl.create(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:494)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:159)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
... 3 more
So I changed the working directory to C:\Program Files (x86)\eSpeak\command_line so that it would find the espeak program.
I then got this error message:
Can't read data file: '\espeak-data\phontab'
Failed to load espeak-data
I tried changing back the working directory to just C:\Program Files (x86)\eSpeak but it then wasn't able to find the espeak program and came back to the first error message.
Any ideas on how I can fix this?
Thanks!

How to Execute Build command in jenkins(Ubuntu)

I need to integrate a simple selenium script with Jenkins.
Can someone please help me to get a shell script code to update in the build section.
Currently, I am tried with run.bat file which returns the following error.
Building in workspace /home/mythos/loremine/Automation_Workspace/JenkinsDemo
[JenkinsDemo] $ cmd /c call /tmp/jenkins2455301809650179322.bat
FATAL: command execution failed
java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
Caused: java.io.IOException: Cannot run program "cmd" (in directory "/home/mythos/loremine/Automation_Workspace/JenkinsDemo"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:250)
at hudson.Proc$LocalProc.<init>(Proc.java:219)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:937)
at hudson.Launcher$ProcStarter.start(Launcher.java:455)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1853)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:427)
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
In Ubuntu, you need to use Execute Shell not Execute Windows Batch Command
remove / in your command as given below. It may solve your problems.
cmd /c call tmp/jenkins2455301809650179322.bat

JLine system terminal issue

I have a problem with JLine 3.9.0. I created a terminal
Terminal terminal = TerminalBuilder.builder().encoding("UTF-8").system(true).build();
First of all it shows a lot of errors, to be precise:
WARNING: Unable to retrieve infocmp for type dumb-color
java.io.IOException: Cannot run program "infocmp": CreateProcess error=2,
Cannot find the specified file
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
at org.jline.utils.InfoCmp.getInfoCmp(InfoCmp.java:547)
at org.jline.terminal.impl.AbstractTerminal.parseInfoCmp(AbstractTerminal.java:187)
at org.jline.terminal.impl.DumbTerminal.<init>(DumbTerminal.java:88)
at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:404)
at org.jline.terminal.TerminalBuilder.build(TerminalBuilder.java:262)
at agh.cs.Court.main.main(main.java:35)
Caused by: java.io.IOException: CreateProcess error=2, Cannot find the specified file
at java.base/java.lang.ProcessImpl.create(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:420)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:151)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
... 7 more
But despite that the program seems to work ALMOST correctly: even after setting encoding to UTF-8 it doesn't see the characters of my alphabet, which is the second issue.

Word Topology deployment error

I am getting the following error when I try to deploy the Word Topology in windows.
I have followed the below link to deploy the word Topology in windows.
http://ptgoetz.github.io/blog/2013/12/18/running-apache-storm-on-windows/
When i deploy and see I am getting the floowing error.
java.lang.RuntimeException: Error when launching multilang subprocess
at backtype.storm.task.ShellBolt.prepare(ShellBolt.java:105)
at backtype.storm.daemon.executor$fn__3493$fn__3505.invoke(executor.clj:689)
at backtype.storm.util$async_loop$fn__457.invoke(util.clj:431)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.IOException: Cannot run program "python" (in directory "storm- local\supervisor\stormdist\WordCount-1-1407303402\resources"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at backtype.storm.utils.ShellProcess.launch(ShellProcess.java:50)
at backtype.storm.task.ShellBolt.prepare(ShellBolt.java:102)
... 4 more
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.(ProcessImpl.java:189)
at java.lang.ProcessImpl.start(ProcessImpl.java:133)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021)
Can anyone help me.
I had the same error.
Look at the compiled source. In the target folder you need all the scripts of the mutlilang available to execute all of them.
Look at target/classes/resources/ if there are any files. If not and if even you do not have the folder in target/classes copy the the resource folder from multilang/resources into the target path.

XMLBeans: java.io.IOException: Cannot run program "C:\xmlbeans\bin\jar":

I'm trying to run XMLBeans:
scomp -compiler "C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe" -cp "C:\Components\*";"C:\Components\jsr173_api.jar";"C:\xmlbeans\lib\xbean.jar";"C:\xmlbeans\lib\xbean_xpath.jar";"C:\xmlbeans\lib\jaxen-1.1-beta-2.jar;" -out S2002PDPIn.jar S2002PDPIn.xsd
It gets an error below:
java.io.IOException: Cannot run program "C:\xmlbeans\bin\jar":
CreateProcess error=2,
The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at org.apache.xmlbeans.impl.tool.CodeGenUtil.externalJar(CodeGenUtil.java:304)
at org.apache.xmlbeans.impl.tool.SchemaCompiler.compile(SchemaCompiler.java:841)
at org.apache.xmlbeans.impl.tool.SchemaCompiler.main(SchemaCompiler.java:272)
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>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 6 more
BUILD FAILED
At first I thought the "C:\xmlbeans\bin\jar" it was looking for was a directory so I just created a folder "jar", but when I run it again the "jar" was referred as a file where I get error:
java.io.IOException: Cannot run program "C:\xmlbeans\bin\jar":
CreateProcess error=5, Access is denied
Please kindly help me how to fix this so that it don't look for "jar" file.
I looked "scomp.cmd" but there is no line that will do this.
Thank you in advance.
You are simply calling more applications, than you expect:
scomp -compiler "C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe" -cp "C:\Components\*";
"C:\Components\jsr173_api.jar";
"C:\xmlbeans\lib\xbean.jar";
"C:\xmlbeans\lib\xbean_xpath.jar";
"C:\xmlbeans\lib\jaxen-1.1-beta-2.jar;" -out S2002PDPIn.jar S2002PDPIn.xsd
This happens because of ";", you would have to enclose the complete classpath with one " and seperate the values by ;.

Categories

Resources