0

我使用以下代码从 Java 应用程序运行 Windows 命令。我尝试了一些 Windows 命令,例如:ver它适用于我的文件。我需要在应用程序中使用的命令是openssl. 我在 Windows 上工作,所以我下载openssl了 Windows。我在命令行窗口中尝试了以下命令,它工作正常。但是,当我从 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"); 
} 
}
4

1 回答 1

0

尝试删除行 p.waitFor();

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

于 2012-12-02T23:36:03.027 回答