Jim's Pages => Java Pages => CmdServer
This program was a learning experience in socket programming and runtime.exec. It enables a client to invoke commands on a remote machine. Our production support people thought it might be handy for problem resolution on machines that they are not usually allowed to Telnet into. Of course, this completely destroys any sense of security you might have regarding the server. Anonymous remote users can connect and do just about anything they like. We might want to secure it with a password before deploying it to production (grin.)
The client accepts user input a line at a time, and forwards the input to the server. When the user enters a command, the server starts the command with runtime.exec() and then connects the command's stdin to the socket input, and the command's stdout and errout to the socket's output. The user interacts with the remote command. When the command ends, the connections are broken and the user interacts with the server again.
As I hinted above, this was a learning experience and not a finished product. Please mail me any constructive comments on how the socket connections are hooked up (kinda tricky threads), how to shut down the server (other than Ctrl-C) and how to improve the command processing ability. For example, on Windows should the server just start cmd.exe and let the user interact with that? The user can start cmd.exe manually now for the same effect.
CmdServer.zip contains source code, executables and JavaDoc.