0

如何从 java 调用 .scpt(applescript) 文件并使用方法将参数从 java 传递到 scpt 文件 Runtime.getRuntime.exec()

Process result = Runtime.getRuntime().exec(cmdArray);

String[] args = {"/usr/bin/osascript", "/Users/uname/Library/Preferences/WebApp/Local\\ Store/spawn/Terminal.scpt" "args1", "args2" "args3" "false"}; 

Process result = Runtime.getRuntime().exec(args);
4

1 回答 1

0

我无法在 Mac 上进行检查,但以下答案适用于 Windows:

    List<String> list = new LinkedList<String>();
    list.add("java");
    list.add("-version");
    ProcessBuilder pb = new ProcessBuilder(list);
    pb.redirectErrorStream(true);
    Process p = pb.start();

    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(p.getInputStream())));
        String line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
    } catch (Exception e) {
        System.out.println(e);
    }

您还可以阅读:

于 2013-09-16T09:45:20.463 回答