Jump to content
Sign in to follow this  
Sudipta

How do I pass the value from AutoIt to Java?

Recommended Posts

Sudipta

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

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  

×