Solved

Using Runtime.exec to open a putty session

Posted on 2009-07-05
6
4,493 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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
difference of if loops 23 62
reverse digits of a number using for loop 5 53
hibernate example for saving data 19 57
by zero exception 10 54
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

820 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