2
我想通過在openSSL文件夾的bin目錄中運行命令。我想從C:\ OpenSSL-Win32 \ bin \目錄運行命令。我需要執行下面的命令: Openssl的DGST -sha1 -sign PrivateKey.pem退房手續Record1.sha1 Message.txt無法使用Runtime.getRuntime()。exec(commandArray,null,directory)從不同目錄運行命令;
我的代碼如下:
import java.io.*;
public class TestExec {
public static void main(String[] args) {
try {
File directory1 = new File("C:\\OpenSSL-Win32\\bin\\");
System.out.println(directory1.toString());
String[] commandArray = {"Openssl dgst -sha1 -sign PrivateKey.pem -out Record1.sha1 Message.txt"};
Process p2 = Runtime.getRuntime().exec(commandArray, null, directory1);
} catch (IOException e) {
e.printStackTrace();
}
}
}
我正在以下IOException異常:
java.io.IOException: Cannot run program "Openssl dgst -sha1 -sign PrivateKey.pem -out Record1.sha1 Message.txt" (in directory "C:\OpenSSL-Win32\bin"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at package1.TestExec.main(TestExec.java:10)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 3 more
請幫我解決這個問題。謝謝。
感謝您的回覆。以下follopwing更改工作:String cmd =「C:\\ OpenSSL-Win32 \\ bin \\ openssl dgst -sha1 -sign PrivateKey.pem -out Record1.sha1 message.txt」; – SGandhi