1

Hi i need to return a value(String) from the autoit.exe to java program(The program which is calling the autoit.exe). So please help me to return value. Below is the code for - Autoit script where i am trying to read a value from the combo box which i am reading correctly. Then i return the value.

Main()

Func Main()

Local Const $dialogTitle = $CmdLine[1]
Local Const $timeout = 5
Local $OTHERARGS= $CmdLine[1]
Local $windowFound = WinWait($dialogTitle, "", $timeout)

Local $windowHandle

If $windowFound Then
    $windowHandle = WinGetHandle("[LAST]")
    WinActivate($windowHandle)
     Local $sString = ControlGetText("","","[CLASS:Edit;INSTANCE:1]")
    ControlClick($windowHandle, "", "[CLASS:Button; TEXT:&Cancel]")
    Return $sString
  Else
    Exit(1)
EndIf
EndFunc

This code is working fine as it is returning 0 as a process exit value. However i am not able to get the return string value. Below is the code for java:

String exePath = "D:\\amit\\Documents\\CancelSave.exe";
exePath = exePath.replace("//", "\\");
Process process = new ProcessBuilder(exePath,""+windowName).start();

// get the input stream of the process and print it
InputStream in = process.getInputStream();

for (int i = 0; i < in.available(); i++) {
 System.out.println("" + in.read());//Here it print nothing

 }
3
  • Please add some example code to demonstrate and show what you've already tried and what part you are getting stuck on. Commented Jul 31, 2014 at 10:21
  • 1
    As far as I know you cannot use a string as the exit code. Returning $sString there probably just causes the process to return 0 or 1 as the exit code. You may want to write the value to the standard output stream (not sure if its possible) and capture it via java. Commented Jul 31, 2014 at 11:05
  • 1
    Exit can only set Integer values. You can create a mapping in your Java program. 1 = ok 2 = Ok, but 3 = Found nothing, ... You could write the value to memory or file or ... and read it with java from there Commented Jul 31, 2014 at 11:36

1 Answer 1

3

ConsoleWrite ( "data" ) writes a string to STDOUT. So instead returning a value from your AutoIt script you should write the value to STDOUT and exit the AutoIt script, then read the value with a stream reader.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.