Solved

How to I run a small Telnet script in Linux from Java and get back the result?

Posted on 2008-10-30
4
1,228 Views
Last Modified: 2012-08-13
Thank you
0
Comment
Question by:kerzner
[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
  • 2
4 Comments
 
LVL 10

Expert Comment

by:kyleb84
ID: 22845973
You want to connect to somewhere via Telnet, but the Telnet client is in Java?
You want this to be a non-interactive procedure?

You'll need a java Telnet client, there's plenty around - then you need to gut it and take out the Telnet protocol handling.

Then you'll need to add on to that class providing automated read/write functions for your application.

It's a fair bit of work but possible.

For a start, here's a Telnet/SSH client in java, source code available.

http://javassh.org/space/start

0
 
LVL 12

Accepted Solution

by:
basav_com earned 500 total points
ID: 22876504
You have to use expectJ here.
http://expectj.sourceforge.net/

More info:
ExpectJ is a Java implementation of the Unix expect utility. ExpectJ provides a Unix expect like support to write Java Programs that communicate with other programs and perform some operation on them.
If you are not familiar with working of the Unix expect utility, please refer to man page of expect. Usage of ExpectJ requires a proper understanding of the Unix expect utility.
For example using ExpectJ you can write a Java program that telnets to a host machine and deletes the contents of /tmp. This program when configured as a cron job will always keep the /tmp under the specified limit.
0
 
LVL 1

Author Comment

by:kerzner
ID: 22876906
kyleb84, the reason I am going this way is because Telnet, when I use it standalone, did work properly. My Java code did not. So I plan to wrap the use of Telnet. I will try your approach if ExpectJ does not work out.
0
 
LVL 1

Author Comment

by:kerzner
ID: 22876918
basav_com,

it sounds like what I need, and I will use it first thing tonight. I vaguely remember having used Unix expect with good results.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

749 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