473,503 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java code for auto answer

21 New Member
Hi ,

I am new to java and i created a program which does an automatic SSH connection from host to a remote machine. I have created a channel from host to remote machine and i am executing certain scripts in the remote machine from the host. This has been done in java. Now the problem is when i run some scripts it prompts for Y/N type of question. I need to answer to that from host machine. Is there anyway to do this.

Eg: In unix script we can use expect function to see what the question is and answer to it. I am looking for a similar function in java.

Thanks ...
Nov 10 '07 #1
3 1742
JosAH
11,448 Recognized Expert MVP
Basically you're starting a Process from your Java program and you want
to talk and listen to/from it. Read the API documentation for the Process class
and see how you can get InputStreams and OutputStreams from it. Use those
streams to read from and write to that other process.

kind regards,

Jos
Nov 10 '07 #2
vinothg
21 New Member
Yes you are correct. I have a InputStream and OutputStream. I know it is unfair to ask more than this. I have an inputStream which displays what happens on the remote machine i.e it shows the script running status. Any idea on how to grep for a particular statement. Just a clue on which function to use. In the mean time let me go through the API ...

Thanks for your quick reply.
Nov 10 '07 #3
JosAH
11,448 Recognized Expert MVP
Yes you are correct. I have a InputStream and OutputStream. I know it is unfair to ask more than this. I have an inputStream which displays what happens on the remote machine i.e it shows the script running status. Any idea on how to grep for a particular statement. Just a clue on which function to use. In the mean time let me go through the API ...

Thanks for your quick reply.
You're welcome of course; such a Process is like a puppet on two strings: you
can read from it and you can write to it. You can also wrap Readers and Writers
around those streams so you can pump Strings into the Process and you can
get Strings out of it. If you want to react 'intelligently' (mind the quotes) from the
Process' output you can even match that output against regular expressions
and act accordingly.

kind regards,

Jos
Nov 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
29418
by: java_helloworld | last post by:
I am trying to print from an applet using the Java Print API. If I run the applet on appletviewer then things work fine i.e. I am able to get the print out. If I run the applet on a browser then...
1
9584
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
36
2013
by: Robert Baer | last post by:
I used Google and found some references for integer in Java. But "int" not only does not work, it also prevents reading X and Y coordinates of the mouse. What i would like to do: 1) Get X and Y...
458
20780
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
16
2099
by: coosa | last post by:
Dear all, I'm familiar with the Set Class in C++ and Java; however, i have been searching in C# for a similar container as in c++ or collection as in java, but couldn't find one. Could some one...
0
8722
by: shaolinman829 | last post by:
My collegue and I are at the point of pulling our hair out. I'm currently writting a little piece of Java code to send an email confirmation page that sends both html and text. Not a problem. In my...
1
4166
by: jynxxxed | last post by:
I've been reviewing some of the threads here and applying some of the advice and still getting the same error. 15:50:26,935 INFO java.sql.SQLException: Could not find stored procedure...
2
2760
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
49
2841
by: aarklon | last post by:
Hi all, See:- http://www.cs.princeton.edu/introcs/faq/c2java.html for C vs Java in number crunching http://husnusensoy.blogspot.com/2006/06/c-vs-java-in-number-crunching.html
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.