0

i'm trying to write a program ,that have toexecute the same code in linux terminal:

openssl req -passout pass:abc -subj /C=US/ST=IL/L=Chicago/O=IBM          Corporation/OU=IBM Software Group/CN=John Smith/emailAddress=smith@abc.ibm.com -new > johnsmith.cert.csr

In the terminal it works fine, but in Java it didn't. I try something like this, but without result.

String[] cmd = { "openssl", "req -passout pass:abc -subj", "/C=US/ST=IL/L=Chicago/O=IBM          Corporation/OU=IBM Software Group/CN=John Smith/emailAddress=smith@abc.ibm.com", "-new > johnsmith.cert.csr" };
Runtime.getRuntime().exec(cmd);

Can you explain me, what i miss.Thanks in advance. Best wishes Andrey

4

1 回答 1

1

您错过了流重定向>是此处不存在的 shell 功能这一事实。

您可以/bin/sh -c使用 java 在命令前添加或重定向输出:

Process proc = Runtime.getRuntime().exec(cmd);
InputStream in = proc.setOutputStream();
OutputStream out = new FileOutputStream("johnsmith.cert.csr");
int b;
while( (b = in.read()) != -1) {
   out.write(b);
}
out.flush();
out.close();

"> johnsmith.cert.csr"现在您可以从命令行中删除。我个人更喜欢这个解决方案。

于 2013-06-19T16:12:40.340 回答