The problem is that the loop that runs on the client program seems to be inifinite so I can only enter one command each time I run the program (i have to force quit out of the loop every time);
Here is the necessary code for the server:
Code: Select all
String[] commands = new String[3];
commands[0] = "cmd";
commands[1] = "/C";
String command, output;
BufferedReader commandInfo = null;
Process current;
while((command = in.readLine()) != null) {
commands[2] = now.decrypt(command);
System.out.println(now.returnDate() + ": " + clientSocket.getInetAddress() + " - " + now.decrypt(command));
current = Runtime.getRuntime().exec(commands);
commandInfo = new BufferedReader(new InputStreamReader(current.getInputStream()));
while((output = commandInfo.readLine()) != null) {
out.println(now.encrypt(output));
}
}Code: Select all
boolean loop = true;
String command, line;
while(loop) {
System.out.print("Command: ");
command = keys.readLine();
out.println(now.encrypt(command));
if(command.equalsIgnoreCase("quit")) {
System.out.println("Exiting...");
loop = false;
} else {
while((line = in.readLine()) != null) {
System.out.println(now.decrypt(line));
}
System.out.println("Command executed successfully\n");
}
}