Java code for auto answer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinothg
    New Member
    • Oct 2006
    • 21

    Java code for auto answer

    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 ...
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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

    Comment

    • vinothg
      New Member
      • Oct 2006
      • 21

      #3
      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.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by vinothg
        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

        Comment

        Working...