title: Run Bash Command from JAVA on AWS EC2 Instance
body: <p>I am new to using AWS SDK on Java. I have created a program to create AWS instances from Java and to check if its running. But I am not able to figure out how to run a bash command on that running instance. Please help!</p>
  
  <pre><code>try
                  {
                      String lscmd = "ls";
                      Process p=Runtime.getRuntime().exec(lscmd);
                      p.waitFor();
                      BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
                      String line=reader.readLine();
                      while(line!=null)
                      {
                          System.out.println(line);
                          line=reader.readLine();
                      }
                  }
                  catch(IOException e1) {
                      e1.printStackTrace();
                  }
                  catch(InterruptedException e2) {
                      System.out.println("Pblm found2.");
                  }
  </code></pre>
  
  <p>But I get an error saying,</p>
  
  <pre><code>java.io.IOException: Cannot run program "ls": 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 java.lang.Runtime.exec(Unknown Source)
  at java.lang.Runtime.exec(Unknown Source)
  at ListInstances.main(ListInstances.java:79)
  </code></pre>
  
  <p>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.(Unknown Source)
      at java.lang.ProcessImpl.start(Unknown Source)
      ... 5 more</p>
  
  <p>I am not sure how to connect to the instance I created and run this command on that instance. </p>