як запусціць каманду openssl з прыкладання java (how to run openssl command from a java application)


問題描述

як запусціць каманду 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 user1810868GreyBeardedGeek)

參考文件

  1. how to run openssl command from a java application (CC BY‑SA 3.0/4.0)

#java #sockets #network-programming #openssl






相關問題

電子郵件地址中帶有 + 字符的 Java 郵件 (Java mail with + character in email address)

如何快速原型化 Java 代碼? (How to quickly prototype Java code?)

如何使用 Maven 在目標(SVN-)服務器上創建 Javadoc? (How to create Javadoc on the target (SVN-) server using Maven?)

為什麼檢查二叉樹有效性的解決方案不起作用? (Why the solution for checking the validity of binary tree is not working?)

Selenium webdriver通過第一個數字找到texy (Selenium webdriver find texy by first digits)

setOnClickListener 沒有在圖像視圖上被調用 (setOnClickListener is not getting called on image view)

繪製多邊形:找不到錯誤 (Drawing Polygon : unable to find error)

半透明 JButton:對像出現在背景中 (Semi-Transparent JButton: Objects appear in Background)

比較同一數組的元素 (Compare elements of the same array)

Java 屏幕截圖小程序 (Java screen capture applet)

Minecraft 1.8.9 Forge Modding 的Java 開發工具包,需要什麼JDK/JRE,代碼是否正確? (Java Development Kit with Minecraft 1.8.9 Forge Modding, What JDK/JRE Is Needed, Is Code Correct?)

java while (resultset.next()) 不返回同一列中的所有數據 (java while (resultset.next()) does not return all data in the same column)







留言討論