Solved

Using Runtime.exec to open a putty session

Posted on 2009-07-05
6
4,287 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now