程序没报错,执行到Runtime.getRuntime().exec(is.readLine());时没看到任何效果,也不继续执行接下来的代码。is.readLine() 是"cmd /k start E://test.txt"。
public class Server {
public static void main(String [] args) {
try {
ServerSocket sersoc = null;
try {
sersoc = new ServerSocket(8399);
} catch (Exception e) {
// TODO: handle exception
}
Socket socket = null;
try {
socket = sersoc.accept();
} catch (Exception e) {
System.out.println("Error."+e);
}
String line = null;
BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter os = new PrintWriter(socket.getOutputStream());
BufferedReader sin = new BufferedReader(new InputStreamReader(System.in));
System.out.println(is.readLine());
Runtime.getRuntime().exec(is.readLine());
while(!line.equals("bye")){
os.println(line);
System.out.println("Server:" + line);
System.out.println("Client:" + is.readLine());
line = sin.readLine();
}
os.close();
is.close();
sersoc.close();
socket.close();
}catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
}
}