Solved

Using Runtime.exec to open a putty session

Posted on 2009-07-05
6
4,433 Views
Last Modified: 2013-11-23
Hi,
I am using a batch file(.bat) to open a putty with a saved session and supplying username and password and logging into it successfully.
I need to use the same logic to open a putty session using Runtime.exec() in java or any methods used in java.
I have given the code below which i use as a batch file.
Please help me with the code for opening a saved session in putty and supplying the username and password for login using a java program
set userid=dinesh
set pswd=1234
start putty -load "session1" -l %userid%  -pw %pswd%

Open in new window

0
Comment
Question by:accetdinesh
  • 3
  • 3
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 20 total points
ID: 24781344
You need to do

Runtime.getRuntime().exec(String.format("cmd.exe /c start putty -load %s -l %s  -pw %s", "session1", userid, pw));

But see particularly:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
0
 

Author Comment

by:accetdinesh
ID: 24781452
CEHJ,
The code is partilally woking for me.
But i have a problem here.I am getting an error "Windows cannot find putty.Make sure you typed the name correctly, and then try again."
Usually i get this error when the "start putty" is invoked in a directory where putty.exe is not present.I am not sure from which directory the "Runtime.getRuntime().exec(String.format("cmd.exe /c start putty")); is executed.
So please help me with the option to invoke this command with a specified path where putty.exe is present.For example if putty.exe is in the path "C:/Documents and settings/dinesh/desktop", please provide me the command to start putty from the given path.

Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24781460
>>"Windows cannot find putty"

It either needs to be in PATH or use the full path to putty.exe. Those are your two options
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Closing Comment

by:accetdinesh
ID: 31599957
It is working perfectly,
Thank you CEHJ.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24781507
:-)
0
 

Author Comment

by:accetdinesh
ID: 24781522
CEHJ,
Is there a way to open a putty session with an ip address instead of using saved session.
If so please help me with the code.

Thanks
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL  on Tomcat 8 47
login jsp example 24 51
going to wrong jsp page 2 22
Html Table Looping (part 2) 5 11
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question