title: Running Shell or System Command in JAVA
body: <pre><code>private void myFunction(String userName){
      String fileName = this.generateFile(userName);
      String[] command = new String[4];
      command[0] = "cmd";
      command[1] = "/C";
      command[2] = "dir";
      command[3] = "7za a "+ userName+".7z  "+ fileName +" -p"+this.password;
      try {  
          Process p = Runtime.getRuntime().exec(command);
          BufferedReader stdInput = new BufferedReader(new
          InputStreamReader(p.getInputStream()));
  
          BufferedReader stdError = new BufferedReader(new
          InputStreamReader(p.getErrorStream()));
  
          while ((s = stdError.readLine()) != null) {
          System.out.println(s);
          }
  
          ProcessBuilder proc = new ProcessBuilder(command[3]);
          proc.start();
      } catch(Exception e) {  
          System.out.println(e.toString());  
          e.printStackTrace();  
      }  
  }
  </code></pre>
  
  <p>I tried both the way of running command line in JAVA. None of them worked. Can anyone enlighten me on what I am doing wrong. I tried for 3 hours but no luck :(</p>
  
  <p>I keep getting this error
  File Not Found
  java.io.IOException: Cannot run program "command"</p>
  
  <p>The same command when I run from cmd, it works. I am using Windows..</p>
  
  <p>Please Help. Thank you!</p>