Solved

Using Runtime.exec to open a putty session

Posted on 2009-07-05
6
4,586 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 162
Delete Android all or certain applications data programmatically 9 146
jmss example java 2 46
Html split(text) 2 45
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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

737 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