Sign in to follow this  
Followers 0
roundar

Running script from java, can't understand ConsoleRead results

5 posts in this topic

#1 ·  Posted (edited)

I'm trying to write to the output stream and read the input stream of a simple Autoit script from java. If I do not use the newLine() character, I get the expected output: a line is sent to auto it, a line is sent to java, and that is repeated. If I add the newLine() character, it seems every cycle an extra line is sent to autoit. Why would this be?

Java:

p = Runtime.getRuntime().exec("Test");

in = new BufferedReader( new InputStreamReader(p.getInputStream()));
out = new BufferedWriter( new OutputStreamWriter(p.getOutputStream()));
int i=0;

out.write("(" + i++ + ") to autoit");
out.newLine();
out.flush();

while ((line = in.readLine()) != null) {

System.out.println(line);

out.write("(" + i + ") to autoit");
out.newLine();
out.flush();

if(i++ > 9)
     p.destroy();
}

Autoit:

Local $line

While (True)

$line = ConsoleRead()

ConsoleWrite( $line & "to java" & @LF )

Sleep(25)

WEnd

Output:

(0) to autoit
to java
(1) to autoit
(2) to autoit
to java
(3) to autoit
(4) to autoit
(5) to autoit
to java
(6) to autoit
(7) to autoit
(8) to autoit
(9) to autoit
to java

Output I Expected:

(0) to autoit
to java
(1) to autoit
to java
(2) to autoit
to java
(3) to autoit
to java
(4) to autoit
to java
(5) to autoit
to java
(6) to autoit
to java
(7) to autoit
to java
(8) to autoit
to java
(9) to autoit
to java

Seems like ConsoleRead() doesn't acknowledge cr or lf as EOF.

Edited by roundar

: ([font=courier new,courier,monospace] EndFunc[/font] : )

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

out.write is creating a new line, in au3 u only add a string

its like this

(0) to autoit | out.newLine();

to java

so where is problem

Edited by jackraymund

thanks you BrewManNH

Share this post


Link to post
Share on other sites

Edited OP, perhaps a bit more clear.


: ([font=courier new,courier,monospace] EndFunc[/font] : )

Share this post


Link to post
Share on other sites

as far as I understood your code (java) you write 9 lines to the STDOUT of the bufferwriter out.

The Autoit it self loops with a sleep of 25ms.

You read than in a while the line (readline)

In my opinion the autoit writes constantly to the console the string: $line & "to java" &@LF

#AutoIt3Wrapper_Change2CUI=Y
#AutoIt3Wrapper_OutFile=exec_autoit.exe
Local $line

While (True)

$line = ConsoleRead()
if @extended>0 Then
ConsoleWrite( $line & "to java - bytes :"&@extended &@LF )
EndIf

Sleep(25)

WEnd

as I'm not much of a java coder here is my au3 of your java code.

#include
#include
#AutoIt3Wrapper_Change2CUI=Y
_DebugSetup("Debug", True,2)
Local $foo = Run("exec_autoit.exe", @ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
Local $line
for $i = 1 to 9
StdinWrite($foo,"("&$i&") to autoit")
$line = StdoutRead($foo)
If @error Then ExitLoop
_Debugout( $line)
sleep(100)
next

ProcessClose($foo)
_Debugout("Exit")

When you run my example WITHOUT the "if @extend" line (remark them) - the output looks like this:

D:\1work>STD_IN_READER.exe

AutoIt:3.3.8.1 Compiled (Os:WIN_7/SP1/X64 OSLang:0407)

(1) to autoitto java - bytes :13

to java - bytes :0

to java - bytes :0

(2) to autoitto java - bytes :13

to java - bytes :0

to java - bytes :0

(3) to autoitto java - bytes :13

to java - bytes :0

to java - bytes :0

(4) to autoitto java - bytes :13

to java - bytes :0

to java - bytes :0

to java - bytes :0

(5) to autoitto java - bytes :13

to java - bytes :0

to java - bytes :0

(6) to autoitto java - bytes :13

to java - bytes :0

to java - bytes :0

(7) to autoitto java - bytes :13

to java - bytes :0

to java - bytes :0

to java - bytes :0

(8) to autoitto java - bytes :13

to java - bytes :0

to java - bytes :0

Exit

and with the if check

D:\1work>STD_IN_READER.exe

AutoIt:3.3.8.1 Compiled (Os:WIN_7/SP1/X64 OSLang:0407)

(1) to autoitto java - bytes :13

(2) to autoitto java - bytes :13

(3) to autoitto java - bytes :13

(4) to autoitto java - bytes :13

(5) to autoitto java - bytes :13

(6) to autoitto java - bytes :13

(7) to autoitto java - bytes :13

(8) to autoitto java - bytes :13

Exit

as always ... au3 fixes the java things :-)

Hint: If you play with your code and the sleep statement in au3 you will get wore results if you add "sleep(1)" as an example. Or better if you eg. add sleep(1000)

Do you agree with the answer?

Share this post


Link to post
Share on other sites

Hey Tankbuster,

I know I am Nectro-bumping this thread. But I just wanted to say thanks your post was very valuable for me working out a way to eliminate standard Windows wrapper scripts to handle arguments to jar files in an app I am building. So thanks!

The OP never responded but I felt the need to. This forum is fantastic, so many intelligent people on here :)
 

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • ags911
      By ags911
      I have a script that has to work on multiple resolutions but each resolution has slightly different co-ordinates due to automatic UI scaling. I have had to make separate files for each but would like to implement them all in one script. I have a similar program written for Java which uses else if statements to use different co-ordinates for each resolution after it has been detected. I'm not good with Java so I would like to implement this on AutoIt before later making a Java version.
       
      This is a snippet of the autoit code I have.
      ToolTip("1 - Search")
      MouseClick("Left", @DesktopWidth *0.823, @DesktopHeight *0.925, 1, 25)
      ToolTip("2 - Buy Now")
      MouseClick("Left", @DesktopWidth *0.83, @DesktopHeight *0.798, 1, 27)
      ToolTip("3 - OK")
      MouseClick("Left", @DesktopWidth *0.555, @DesktopHeight *0.596, 1, 15)
      ToolTip("4 - OK Clear Error")
      MouseClick("Left", @DesktopWidth *0.49, @DesktopHeight *0.597, 1, 30)
      ToolTip("5 - Back to Search")
      MouseClick("Left", @DesktopWidth *0.161, @DesktopHeight *0.108, 1, 15)
       
      This is a snippet of a java code I used.
      Thanks.
      private static void goToSearch(double maxX, double maxY, Robot bot) throws InterruptedException {     int currentX = 0;     int currentY = 0;     if (maxX == 2650 && maxY == 1440) {         currentX = 734;         currentY = 1316;     } else if (maxX == 1920 && maxY == 1200) {         currentX = 551;         currentY = 1096;     } else if (maxX == 1920 && maxY == 1080) {         currentX = 551;         currentY = 1042;     } else if (maxX == 1680 && maxY == 1050) {         currentX = 482;         currentY = 959;     } else if (maxX == 1440 && maxY == 900) {         currentX = 413;         currentY = 822;     } else if (maxX == 1366 && maxY == 768) {         currentX = 392;         currentY = 741;     } else if (maxX == 1280 && maxY == 800) {         currentX = 367;         currentY = 731;
    • Psyllex
      By Psyllex
      I have a super simple login screen I'm trying to access that is written in java.  My java testing tools can't access the login screen because it's a modal window.  So I figured I'd see if AutoIt can manipulate 'something' on it.  I can enter text within the text boxes for user name and password.  But I can't see to click on the login button.  I've tried just tabbing to it and hitting the enter key (as I really wouldn't have to be completely interacting with the frame).  But that didn't work.  I was hoping to throw it some coordinates and just double click in that relative area, but when I get the whole " ==> Subscript used on non-accessible variable.:" when I attempt to use ControlGetPos() I'm assuming because it can't truly interact with the Java frame.  So I'm kind of stuck here...can't use AutoIt, can't use a Java automation testing tool to do this due to the modal issues.  Does anyone have any ideas?  My code is below though I think it's less to do with code and more what AutoIt can and can't do.
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Local $hWnd = WinActivate("[CLASS:sunawtframe]", "Login") Local $aPos = ControlGetPos($hWnd, "[CLASS:SUNAWTFRAME]", "Login") Local $myXPos = $aPos[0] + 420 Local $myYPos = $aPos[1] + 270 Send("guest") Send("{TAB}") Send("guest") Send("{TAB}") ;Tried Control Click it failed ControlClick($hWnd, "", "Login") ;Tried Mouse Click and that failed MouseClick("Left", $myXPos, $myYPos, 2)  
      Thanks for any help!
    • fosil
      By fosil
      Hi everyone.

      I'm currently working a program that constantly prints out log files through "consolewrite" and the "#AutoIt3Wrapper_Change2CUI=y" wrapper.

      Part of this program requires me to run a batch script.

      My issue is the batch script launches from the same window as consolewrite. I need the batch file to be launched through a different window as currently this causes an issue with the logs (which need to be very precise) but also causes the batch file to produce some funny behavior...

      Does anyone know how I can force the file to run on a second DOS window?

      Thanks in advance!!!
       
      Edit: Im using the "run" command if that helps. I tried "shellexecute" but that seemed to not launch the batch scripts at all.
    • initspawn
      By initspawn
      Hello,
      I've been trying to automate a process to check in the GUI of a Java program for a certain condition. When I use the Autoit Window information tool I don't get anything under the control tab, which seems to be normal for a Java program. I've been able to automate what I need using ControlSend and checking for the condition using ImageSearch but the Java program will not accept ControlSend unless it is the active window. I'd like to run the script while the window is inactive so I can still use the PC but haven't been able to come up with a solution other than a virtual machine. I even tried sysinternals desktops to create a second virtual desktop but that just causes WinActivate to return a failure after you switch to another virtual desktop. Does anyone have any ideas for getting a window to think its active when its not or an alternative to ControlSend that may work?
      Thanks. 
    • Muhammad_Awais_Sharif
      By Muhammad_Awais_Sharif
      Hi
      I have Java 8 installer 
      I want to automate it's installation process. 
      I have found silent installation method but I want to install it using controls clicking like as normal user do 
      But I don't find any control using  AutoIt v3 Window Info 
      How I can find it's control buttons ?
      Thank you