Jump to content

Java library and command line management


Recommended Posts

😉Hello, excuse my English. I have been with Autoit since it was born and it has always seemed like a great job from jon. I just want with this installment to briefly explain the construction model of a java jar library and its subsequent handling through autoit. One of the benefits this brings is to bring some of the power of java to our scripts. This is really simple:
First: create a "java application" project in an IDE (NetBeans for example). This will create the java file that has the input method "public static void main (String [] args) {...}" Here is a practical example of content the this file:

package javaapplication1;

 * @author
public class JavaApplication1 {

     * @param args the command line arguments
    public static void main(String[] args) {
        // TODO code application logic here
        OutPrintInSTDOUT(args[0], args[1]);
    private static void OutPrintInSTDOUT(String y, String code){
        System.out.println(y + ":: "+ code);

Look in this example that the program handles two arguments per command line, which are obtained in "args [0]" and "args [1]". There can be many more as is convenient.

An example method has been created (OutPrintInSTDOUT) that prints a result at the output of the system. This result is what we capture in Autoit as we will see later. This is the basic structure. From this idea you can build a whole library of methods and functions that process values by command line input or simply respond to those input values. Can you see it?

Second: In autoIt, how to run the jar file, pass values to it by command line and get the output value:

#include <AutoItConstants.au3>

; Script Start - Add your code below here
;java -jar JarExample.jar "arg 1"

Global $iPID = Run("java -jar JavaApplication1.jar Arg1 Arg2","",@SW_HIDE, $STDOUT_CHILD)
Global $sOutput = ""

While 1
    $sOutput = StdoutRead($iPID)
    If @error Then ExitLoop ; Exit the loop if the process closes or StdoutRead returns an error.
    ConsoleWrite( $sOutput)

Output on Scite console:

>Running AU3Check (  from:C:\Program Files (x86)\AutoIt3  input:D:\Nuevo AutoIt v3 Script.au3
+>01:21:48 AU3Check ended.rc:0
>Running:(\Program Files (x86)\AutoIt3\autoit3_x64.exe "D:\Nuevo AutoIt v3 Script.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
Arg1:: Arg2
+>01:21:48 AutoIt3.exe ended.rc:0
+>01:21:48 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.508

Some considerations:

  • Obviously we must have java installed on our computer: Java donwload
  • If the java IDE cannot generate the jar file try downgrading the java sdk. It worked for me in version 8.
  • We must pass through the command line the amount of suitable parameters. If we pass less than those that are handled inside the main () of the java file it will give an error.

I hope this little tutorial can help you. In the future I will work on a Spanish version of AutoIt Help. See you soon. <novi>.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...