0

I've tried with:

ProcessBuilder pb = new ProcessBuilder("osascript script.scpt");
pb.inheritIO();
pb.directory(new File("bin"));
try {
    pb.start();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

but I always get the error "no such file or directory". I've tried also with:

Runtime.getRuntime().exec("osascript script.scpt");

but nothing happens.

I also tried using this string in both the snippets above, but nothing changed.

osascript -e 'tell application \"Safari\" to quit' 
General Grievance
  • 4,555
  • 31
  • 31
  • 45
JaneLilep
  • 79
  • 1
  • 9
  • 1
    You should use `ProcessBuilder proc = new ProcessBuilder("osascript", "script.scpt");` – Daniele Jun 09 '18 at 20:37
  • Dupe https://stackoverflow.com/questions/11593849/java-execute-process-on-linux and https://stackoverflow.com/questions/6856028/difference-between-ProcessBuilder-and-Runtime.exec . Note you are not running a bash command; `ProcessBuilder` or `Runtime.exec` runs a program in a fashion similar in _some_ respects to a shell (including bash) command but not identical. – dave_thompson_085 Jun 09 '18 at 23:23

1 Answers1

0

I was able to fix the issue by using this

ProcessBuilder proc = new ProcessBuilder("osascript", "script.scpt");

This is because there's no tokenisation: the command to run is assumed to have already been tokenised.

JaneLilep
  • 79
  • 1
  • 9