I want to write a script that does the following:
- Start listening on a random available localhost TCP port.
- Start a certain external program passing the port number as an argument.
- Accept a single connection to the server socket.
- Send the script’s standard input into the socket, and the socket’s output to standard output.
- Exit when the external program exits.
The ideal solution would be a shell script invoking some reasonably standard tools, so if anybody can come up with a way to do that, well, that would be the perfect answer. If that proves intractable, a Ruby implementation wo开发者_运维知识库uld be convenient for me. Failing that, I’ll take any workable implementation.
P.S. I’m pretty new here, so please let me know if this question is too general or if it doesn’t belong for some other reason (maybe "please implement X for me" is frowned upon?).
Have you tried netcat ? Both listener and client can be done with nc.
精彩评论