【问题标题】:how to run openssl command from a java application如何从 Java 应用程序运行 openssl 命令
【发布时间】:2012-12-02 20:56:49
【问题描述】:

我使用以下代码从 Java 应用程序运行 Windows 命令。我尝试了一些 Windows 命令,例如:ver,它适用于我的文件。我需要在应用程序中使用的命令是openssl。我在 Windows 上工作,所以我为 Windows 下载了openssl。我在命令行窗口中尝试了以下命令,它工作正常。但是,当我从 Java 应用程序中尝试它时,我得到的只是完成。我没有得到输出。有人可以帮忙吗?

代码如下:

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"); 
} 
}

【问题讨论】:

    标签: java sockets network-programming openssl


    【解决方案1】:

    尝试删除该行 p.waitFor();

    waitFor() 等待进程结束。因此,当您获得 InputStream 时,该过程已经完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-10
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 2013-09-09
      相关资源
      最近更新 更多