EamonB Posted August 19, 2014 Posted August 19, 2014 (edited) I am doing some simple tests in eclipse where I pass parameters from Java code into my AutoIt exe successfully. But now I want to see if there is a way in Java to capture whether or not the AutoIt exe ran correctly (possibly by having the executable return a boolean that can be passed back to the Java code) Here is my original sample code String[] cmd = new String[3]; cmd[0] = AutoItScripts.compareDocsWord; cmd[1] = "C:\\Users\\Eamon\\Desktop\\file1.doc"; cmd[2] = "C:\\Users\\Eamon\\Desktop\\file2.doc"; Runtime.getRuntime().exec(cmd); Although I understand the code below obviously doesn't work, I was wondering if there was any sort of way to pass the result of the AutoIt exe back into Java in a way similar to this example int x = 5; String[] cmd = new String[3]; cmd[0] = AutoItScripts.compareDocsWord; cmd[1] = "C:\\Users\\Eamon\\Desktop\\file1.doc"; cmd[2] = "C:\\Users\\Eamon\\Desktop\\file2.doc"; Boolean result = Runtime.getRuntime().exec(cmd); if (result==false) x+=7; Edited August 19, 2014 by EamonB
AdmiralAlkex Posted August 19, 2014 Posted August 19, 2014 '?do=embed' frameborder='0' data-embedContent>> It's okay to bump after 24 hours, but please don't create multiple threads on the same issue. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
Moderators Melba23 Posted August 19, 2014 Moderators Posted August 19, 2014 EamonB,What he said. Threads merged. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Solution EamonB Posted August 19, 2014 Author Solution Posted August 19, 2014 (edited) My bad. I didn't know how to delete my previous post so I created a new one. Also, for anyone else's reference, I figured out how to pass values from the executable back into Java. AutoIt has a thing called Exit return values. Scripts normally return an exit value of 0 if the script executed properly but you can set the exit value to any number above 0 that you want depending on what condition you want to return to Java. For example, this is my autoit script same code: $var = 2 if $var > 4 Then Exit(1) Else Exit(2) EndIf Since $var is less than 4, the script will have the exit value of 2 Here is my corresponding Java code that calls the Autoit exe: String[] cmd = new String[1]; cmd[0] = AutoItScripts.test; Process result = Runtime.getRuntime().exec(cmd); result.waitFor(); if (result.exitValue()==1) System.out.println("YAY!"); else System.out.println("boo"); You can expect the console to print out "boo" instead of "YAY!" because the exit value is not 1 (it's 2 because the value of $var was less than 4). NOTE: keep in mind that you have to add the result.waitFor() function (waits for the exe to finish running) in your java code before you verify the exit value result because otherwise the java code is going to check the exit value before the executable even finishes running. Hopefully that helps anyone else that had a similar problem to me!! Edited August 19, 2014 by EamonB
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now