Jump to content

EamonB

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by EamonB

  1. 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!!
  2. 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;
  3. Thank you Tekk! I tried that and it runs perfectly. I now know you are supposed to pass the location of the executable as the value of the first index of the cmdArray
  4. Thank you guys for the reply but the parameters are still not being passed. I understand that you are supposed to pass the parameters to the AutoIt exe by calling the Runtime.getRuntime().exec(exeLocation, cmdArray) and then AutoIt exe will use the cmdArray that was passed as the $CmdLine array that I call in the script, yet I am still getting an issue I changed up the script code to explicitly print each value of the $CmdLine array, but only the first line gets called and the result is incorrectly "0". On top of that, the other two message box's don't even appear. Am I doing something wrong? My Java Code: public class test { public static void main(String[] args) throws I0Exception, InterruptedException { String[] cmd = {"test", "testl", "test2"}; Runtime.getRuntime().exec("C:/Users/Eamon/Desktop/test.exe", cmd); } } My Autoit Script code: #include <Word.au3> #include <MsgBoxConstants.au3> MsgBox(0, "First Argument", $CmdLine[0]) MsgBox(0, "First Argument", $CmdLine[1]) MsgBox(0, "First Argument", $CmdLine[2]) Resulting msg box:
  5. I want to do a simple test in eclipse where I pass parameters from Java code into my AutoIt exe where I print out the $cmdLineRaw value in a message box. Attached in the code I have in Java and the AutoIt Script code. Yet, when I run the code in Eclipse, the corresponding empty message box appears. I know I am not populating the $CmdLine array and passing in the parameters to the executable correctly, but I am not sure what I have overlooked. Any help would be appreciated! Thank you! My Java code: public class test { public static void main(String[] args) throws I0Exception, InterruptedException { String[] cmd = {"test", "testl", "test2"}; Runtime.getRuntime().exec("C:/Users/Eamon/Desktop/test.exe", cmd); } } My AutoIt script code: #include <Word.au3> #include <MsgBoxConstants.au3> MsgBox($MB_SYSTEMMODAL, "Print", $CmdLineRaw, 10) Resulting message box:
×
×
  • Create New...