1

How would I go about executing a .SH file (this is localhost, no remote connection or anything)? I've seen lots of Runtime.exec and other things when I searched but those didn't seem to work.

This is Java 6. Also if it matters, all the SH is doing is moving two folders around.

Thanks!

latonz
  • 1,601
  • 10
  • 21
DannyF247
  • 628
  • 4
  • 14
  • 35

2 Answers2

5

You could use ProcessBuilder

 ProcessBuilder pb = new ProcessBuilder("myshell.sh", "myArg1", "myArg2");
 Process p = pb.start();
 BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
 String line = null;
 while ((line = reader.readLine()) != null)
 {
    System.out.println(line);
 }
fwonce
  • 397
  • 1
  • 5
  • 18
Martin
  • 7,089
  • 3
  • 28
  • 43
0

You may also give some consideration to the JSch library if you do not want to make your code platform-dependent by directly invoking OS commands.

Edwin Dalorzo
  • 76,803
  • 25
  • 144
  • 205