Код: Выделить всё
ProcessBuilder process3 = new ProcessBuilder(
"openssl" ,
"req",
"-new",
"-key",
"-",
"-subj",
"/C=IN/ST=TamilNadu/L=Chennai/O=Inspoworks Private Ltd/OU=IT solutions/CN=com.radnus.com/emailAddress=sundar@inspoworks.com",
"-out","-");
Process p3 = process3.start();
try(BufferedOutputStream bos1 = new BufferedOutputStream(p3.getOutputStream())){
bos1.write(privatekey.getBytes());
bos1.flush();
}
String csr1 = readOutput(p3.getInputStream());
System.out.println(csr1);
exitcode = p3.waitFor();
if (exitcode != 0) {
System.err.println(exitcode);
System.err.println(readOutput(p3.getErrorStream()));
}
System.out.println(csr1);
}
//general method to read terminal output
public static String readOutput(InputStream inputstream) throws IOException {
StringBuilder sb = new StringBuilder();
try (InputStreamReader reader = new InputStreamReader(inputstream)) {
int ch;
while ((ch = reader.read()) != -1) {
sb.append((char)ch);
}
}
return sb.toString();
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... acode-usin