如何从 Java 执行程序

How to execute a program from Java

我想知道如何从我的 Java 程序中执行我的 AutoHotKey 脚本。问题是我不确定实际执行此操作的最佳方法,因为当我执行此操作时出现错误...

Runtime runtime = Runtime.getRuntime();

    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    try {
        String actualPath = "C:\Users\me\Desktop\Coding\test.ahk";
        String autoHotKeyScript = "C:\Program Files\AutoHotkey";
        runtime.exec(new String[] {autoHotKey, actualPath});
    } catch (IOException e) {
        e.printStackTrace();
    }

出现错误:

Cannot run program "C:\Program Files\AutoHotkey": CreateProcess error=5, Access is denied

    Runtime runtime = Runtime.getRuntime();

    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    try {
        runtime.exec("C:\Program Files\AutoHotkey.exe C:\Users\me\Desktop\Coding\test.ahk");
    } catch (IOException e) {
        e.printStackTrace();
    }

在您的 ahk 脚本前添加 AutoHotkeyU64.exe