Results 1 to 8 of 8
  1. #1
    subhayan is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default Using input and output streams for remote interprocess communication

    Hi All,

    I have a command line application in Linux which takes user input from console.

    I need to write a program to interact with the application - basically to write inputs to and read outputs from the application.

    I found here how to do it if the application is running locally.
    http://publib.boulder.ibm.com/infoce...a/interpro.htm

    But I wanna to do it remotely that is running the application on a different machine and interacting with it programmatically in Java.

    Does anybody have any idea how to do it?

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    So do you want to do client/server socket solution?

    If answer is yes you can start from networking tutorial on this forum:

    http://www.java-forums.org/java-tuto...amming-ii.html

    are you OK with this?

  3. #3
    subhayan is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    No, I didn't want to do a client-server.

    I think I find an alternative.

    Do this

    String commandLine[] = {"ssh", "host_name", "commandApp"};
    Process proc = Runtime.getRuntime().exec(commandLine);

    and then proceed as the link suggests in the previous post.

  4. #4
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    Do you have to create key pairs and exchange them before
    you run this ssh command on remote machine?
    How many clients are we talking about and is it important at all?

    If you gonna use Runtime I strongly suggest reading article "When Runtime.exec() won't":

    When Runtime.exec() won't - JavaWorld

    good luck!

  5. #5
    subhayan is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    I am just reading outputs from the app's standard output and writing data to it's stabdard input.

    I call ssh to connect to remote machine. I am using just 1 client.

    What do you mean by if it is important? What is it that you want to know if is important?

    Thanks for the link.

  6. #6
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    You are welcome.

    In case of many clients you would have to exchange key pairs with all of them, so that was the reason I asked you, but if it only 1 client you are cool.

    Can u make it work now?

  7. #7
    subhayan is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    Though it's a bit off topic, I don't quite understand why I need to send key-value pair in case of more than one client.

    And yes, it's working now.
    To add one more tit-bit, when you write to the output stream of the application always flush the stream right after writing. I think it's because the buffered output doesn't actually write untill it is filled up.

    Here is an example:

    outStream = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
    outStream.write("\r\n");
    outStream.flush();

  8. #8
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    Streams and buffers flush on close().
    and there's flushing for buffer only when the buffer is full.
    There are auto flushing cases is ome classes and their methods by default like PrintWriters printing the end of the line.
    Default buffer size for a BufferedInputStream is 8KB.

Similar Threads

  1. help with data output, input
    By collin389 in forum New To Java
    Replies: 3
    Last Post: 11-11-2009, 06:34 PM
  2. output streams
    By andre1011 in forum Networking
    Replies: 1
    Last Post: 03-24-2009, 09:18 AM
  3. Single XSD Creation for input/output
    By lavanya82 in forum XML
    Replies: 0
    Last Post: 03-13-2009, 01:02 PM
  4. ObjectInput/Output Streams
    By Rhesus21 in forum Networking
    Replies: 3
    Last Post: 07-30-2008, 02:26 AM
  5. Runtime.exec(), handling input and output streams
    By crookshank in forum New To Java
    Replies: 0
    Last Post: 06-05-2008, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •