有没有办法使用来自java的参数运行脚本?不是可执行文件,而是 AutoHotKey 脚本。
我试过这个,但由于它不是一个有效的可执行文件,它不起作用。
控制类:
package org.bsep.acp;
import java.io.IOException;
/**
* This class allow you to send string to your
* computer as keystrokes.
*
* escape car is '
* special char are {space}, {Enter}, {F1}, {F2}, etc
*
* @author Eildosa
*/
public class StringSender {
Runtime runtime;
private final static String AHK_BRIDGE = "C:\\perso\\WorkspaceScripts\\skyrimTools\\src\\org\\bsep\\acp\\ahkBridge.ahk";
public StringSender() {
runtime = Runtime.getRuntime();
}
public void sendString(String data) throws IOException, InterruptedException {
runtime.exec(new String[] { AHK_BRIDGE, data} );
Thread.currentThread();
Thread.sleep(1000);
}
}
测试 :
Runtime runtime = Runtime.getRuntime();
runtime.exec(NOTEPAD);
Thread.currentThread();
Thread.sleep(4000);
StringSender stringSender = new StringSender();
stringSender.sendString("Writing from java through AHK.");
例外 :
Exception in thread "main" java.io.IOException: Cannot run program "C:\perso\WorkspaceScripts\skyrimTools\src\org\bsep\acp\ahkBridge.ahk": CreateProcess error=193, %1 n?est pas une application Win32 valid
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:485)
at org.bsep.acp.StringSender.sendString(StringSender.java:25)
at org.bsep.acp.VariousTests.ahkBridgeTester(VariousTests.java:23)
at org.bsep.acp.VariousTests.main(VariousTests.java:13)
Caused by: java.io.IOException: CreateProcess error=193, %1 n?est pas une application Win32 valid
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:376)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 5 more
翻译:这不是一个有效的 win32 应用程序。
谢谢。