Jump to content

How do I pass the value from AutoIt to Java?


Recommended Posts

Hi All,
I am new to autoit. I am trying to run some simple unix commands through java and return some value from unix to java program . Here is the overall flow:
1> Java (CallPutty.java ) is opening the putty application and login with Username & password.

2> I am calling an autoit script (PuttyCommand.exe) .

3>autoit script is passing & running commands in putty.

I am taking the count of files in a specific folder and I want to pass the count o into the java program.

I know , the code written in italic & underlined  font , will not work.This is just for reference and I need help to build the logic with correct code  :).

Code snippet from CallPutty.java


public static void main (String args[]) throws AWTException, IOException, InterruptedException

{

CallPutty c=new CallPutty();

Runtime r = Runtime.getRuntime();

Process p;

String username = "Userid";

String password = "Password";

String serverString = "Server";

String s = "C:\\Program Files (x86)\\Simon Tatham\\PuTTY\\putty.exe -ssh -l "+username+" -pw "+password+" "+serverString+"";

try

{

//open the putty session with the above given username, password and server

p = r.exec(s);

} catch (Exception e)

{

System.out.println(e);

e.printStackTrace();

}

//calling the autoit script to run unix command

int count = Runtime.getRuntime().exec("C:\\Users\\workspace\\HelloWorld\\AutoIt_Script\\PuttyCommand.exe");

try

{

Thread.sleep(2000);

}

catch (Exception e)

{

}

}

Code Snippet from PuttyCommand.exe

ControlFocus("auq4094l.unix.anz - PuTTY","","")

WinSetState("auq4094l.unix.anz - PuTTY","",@SW_MAXIMIZE)

Sleep(1000)

Send( "cd /data/out/GCR/NZ/new" & "{ENTER}" )

Sleep(3000)

$count = Send( "ls | wc -l " & "{ENTER}" )

return $count

Link to post
Share on other sites
  • Moderators

You can capture the STDOut of another program in Java pretty easily. Google it and you will see dozens of examples; below is just one:

https://stackoverflow.com/questions/14542448/capture-the-output-of-an-external-program-in-java

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...