I have the following code to execute Openssl command and read the ouptut produced by the command through Java Runtime
public void executeCmd() throws IOException {
Runtime rt = Runtime.getRuntime();
String[] commands = new String[]{"openssl", "rsa", "-noout", "-modules", "-in", "myPathToKeyFile", "|", "openssl", "sha256"};
Process proc = rt.exec(commands);
BufferedReader stdInKey = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String s = null;
while ((s = stdInKey.readLine()) != null) {
System.out.println(s);
}
}
When i run the command through Cmd, it is working and I am able to see the output
But When I run through this code, I am getting following error :
Exception in thread "main" java.io.IOException: Cannot run program "openssl": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:485)
at com.renault.vnext.business.impl.CmdRunner.executeCmd(CmdRunner.java:22)
at com.renault.vnext.business.impl.CmdRunner.main(CmdRunner.java:10)
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:444)
at java.lang.ProcessImpl.start(ProcessImpl.java:140)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 4 more
Note : I have set upto bin folder in the path variable
I am able to run the command in cmd and get the output. My requirement is to get the stdin value from the command ouptut
Much appreciating your help!