Здесь я пытаюсь открыть блокнот в AutoIt с Java. Однако я не могу открыть его с помощью следующего кода.
public class Notepad {
public static String jvmBitVersion() { //returning the JVM Version
return System.getProperty("sun.arch.data.model");
}
public static void main(String[] args) throws InterruptedException {
String jacobDllVersionToUse;
System.out.println("JVM version is: " +jvmBitVersion());
if (jvmBitVersion().contains("32")) { //Checking for the JVM Version
jacobDllVersionToUse = "jacob-1.18-M2-x86.dll"; // If the version is 32- bit use this.
}
else { // enter code here
jacobDllVersionToUse = "jacob-1.18-M2-x64.dll"; // if the version is 64-bit go for this
}
File file = new File("lib", jacobDllVersionToUse); // file location for jacob
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
x.run("notepad.exe"); // trying to open the notepad
x.winActivate("Untitled - Notepad"); // waiting for the notepad to open
x.winWaitActive("Untitled - Notepad");
x.send("This is some text"); // Once the notepad is open write into it.
}
}
Если вместо notepad.exe я даю calc.exe, он работает нормально. Если я открываю блокнот вручную после запуска, это код, который записывается в блокнот.