Results 1 to 8 of 8
- 02-23-2010, 10:33 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
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?
- 02-23-2010, 11:31 PM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
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?
- 02-23-2010, 11:46 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
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.
- 02-24-2010, 12:34 AM #4
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
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!
- 02-24-2010, 03:32 AM #5
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
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.
- 02-24-2010, 12:43 PM #6
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
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?
- 02-24-2010, 06:45 PM #7
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
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();
- 02-24-2010, 08:00 PM #8
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Similar Threads
-
help with data output, input
By collin389 in forum New To JavaReplies: 3Last Post: 11-11-2009, 05:34 PM -
output streams
By andre1011 in forum NetworkingReplies: 1Last Post: 03-24-2009, 08:18 AM -
Single XSD Creation for input/output
By lavanya82 in forum XMLReplies: 0Last Post: 03-13-2009, 12:02 PM -
ObjectInput/Output Streams
By Rhesus21 in forum NetworkingReplies: 3Last Post: 07-30-2008, 01:26 AM -
Runtime.exec(), handling input and output streams
By crookshank in forum New To JavaReplies: 0Last Post: 06-05-2008, 02:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks