title: Not able to run a command from different directory using Runtime.getRuntime().exec(commandArray, null, directory);
body: <p>I want to run the command in bin directory of openSSL folder through. I want to run the command from C:\OpenSSL-Win32\bin\ directory. And I need to execute the following command:
  Openssl dgst -sha1 -sign PrivateKey.pem -out Record1.sha1 Message.txt</p>
  
  <p>My code is as follows: </p>
  
  <pre><code>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();  
      }  
  }  
  } 
  </code></pre>
  
  <p>I am getting the following IOException:</p>
  
  <pre><code>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.&lt;init&gt;(Unknown Source)
      at java.lang.ProcessImpl.start(Unknown Source)
      ... 3 more
  </code></pre>
  
  <p>Kindly help me resolve this issue.Thanks.</p>