Java运行时类 - 无法在cmd提示符中进行cd

时间:2014-09-26 04:23:47

标签: java runtime.exec

这个程序是从java创建服务器证书而不打开命令提示符(至少是手动)这段代码执行成功,但我看不到我的文件" server.jks"既不在" cd" ed目录中,也不在cmd加载的默认目录中(c:\ Documents and Settings \ administrator)。我对在指定目录中生成更感兴趣。帮助我改变我的代码来做到这一点。

  public class SslKeytool
 {
public void createServerCertificate(String dn, String alias, String validity, String keystoreName, String keypass, String storepass, String drive, String path)
{
    try
    {
        Runtime runtime = Runtime.getRuntime();
        String result;
        result = "keytool -genkeypair ";
        result = result + "-alias " + alias + " ";

        result = result + "-keyalg RSA -dname " + dn + " -validity " + validity + " -keypass" + keypass + " -keystorename " + keystoreName
                + " -storepass" + storepass;
        runtime.exec("cmd " + drive + ":");
        runtime.exec("cmd cd " + path);
        runtime.exec("cmd " + result);
    }
    catch (Exception e)
    {
        System.out.println("Whoa! Something went wrong! please make sure that you read the API ");
        e.printStackTrace();
    }
}

public static void main(String[] args)
{
    SslKeytool obj = new SslKeytool();
    obj.createServerCertificate("CN=LCMS,OU=Software Solutions,O=Live Connections,L=Chennai,S=TamilNadu,C=Ind", "servercert", "365", "abc.jks", "lcmsauth"
            , "lcmsauth", "f", "/keytest");

}
}

0 个答案:

没有答案