1

I'm trying to replicate PHP's exec function in a Java application. Here's the PHP code:

exec('C:/executer.au3');

And here is the Java code:

Runtime.getRuntime().exec("C:/executer.au3");

When I run that I am getting an IOException saying:

Exception in thread "main" java.io.IOException: Cannot run program "C:/executer.au3": CreateProcess error=193, %1 is not a valid Win32 application
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    at java.lang.Runtime.exec(Runtime.java:615)
    at java.lang.Runtime.exec(Runtime.java:448)
    at java.lang.Runtime.exec(Runtime.java:345)
    at Executer.execute_captcha_check(Executer.java:248)
    at _ProjectAmsterdam.main(_ProjectAmsterdam.java:36)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:189)
    at java.lang.ProcessImpl.start(ProcessImpl.java:133)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021)
    ... 5 more

I'm a bit out of my element, how can I get this au3 file to open in Java?

1
  • 5
    You have to execute by doing something like: autoit.exe C:/executer.au3.
    – user142162
    Mar 11, 2012 at 19:00

2 Answers 2

4

The file you mention is an autoscript file that does not do anything by itself. Like a text file.

You probably need to supply the program that will run the file - the Autoit.exe program for example.

Runtime.getRuntime().exec("/Path/To/Autoit.exe C:/executer.au3");

Along those lines - I cannot test at the moment.

The PHP exec version may somehow trigger the default program for .au3 files. That's just a guess.

1
  • You're exactly right, this worked. I just can't accept the answer yet :) Mar 11, 2012 at 19:16
2

Although running AutoIt.exe with the script as a command line argument works, and is probably fine in most situations, I'd like to present this as an alternative.

The PHP exec function probably uses ShellExecute rather than just running it. This looks in the registry to find the associated action for .au3 files.

A similar thing can be done in java using Desktop.getDesktop().open(SomeFile).

However, AutoIt allows the user to check at install time whether they want the default action to be edit the script file or run it. Dependant on the setting there, this could mean you end up opening the script in a text editor, rather than running it as intended. ShellExecute (the windows API function) provides an option of what verb to use (default being open). This would allow you to always use the run verb, but means using the windows function from java, which means a wrapper like this. Although it would mean a lot more effort, you'd be guaranteed it would work on any valid AutoIt installation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.