問題描述
як запусціць каманду openssl з прыкладання java (how to run openssl command from a java application)
I use the following code to run Windows commands from Java application. I tried some windows commands such as: ver
and it works file with me. The command I need to use in the application is openssl
. I work on Windows, so I downloaded openssl
for Windows. I tried the following command in the command line window, and it works fine. But, when I try it from the Java application, all what I get is Done. I don't get the output. Can anybody help ?
Here is the code:
import java.io.*;
public class DebianChecker
{
public static void main(String args[])
{
try
{
Process p=Runtime.getRuntime().exec("cmd /c openssl s_client ‑connect
gmail.com:443");
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch(IOException e1) {}
catch(InterruptedException e2) {}
System.out.println("Done");
}
}
‑‑‑‑‑
參考解法
方法 1:
Try removing the line p.waitFor();
waitFor() waits for the process to end. So, by the time you get the InputStream, the process has already completed.
(by user1810868、GreyBeardedGeek)