Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-30
4
Medium Priority
?
1,287 Views
Last Modified: 2012-08-13
Thank you
0
Comment
Question by:kerzner
  • 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.
Suggested Courses

877 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