Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Runtime.exec to open a putty session

Posted on 2009-07-05
6
Medium Priority
?
4,914 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 80 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

604 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