| | |
| | | @Value("${socket.port}") |
| | | private int port; |
| | | |
| | | /** |
| | | * Socket的端口 |
| | | */ |
| | | @Value("${cmd.runPy}") |
| | | private String runPy; |
| | | |
| | | private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
| | | |
| | | /** |
| | |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
| | | PrintWriter out = new PrintWriter(socket.getOutputStream(), true); |
| | | |
| | | exec(runPy); |
| | | |
| | | // 将用户输入的信息发送给服务端 |
| | | out.println(msg); |
| | | |
| | |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 执行命令 |
| | | * |
| | | * @param cmd 命令 |
| | | */ |
| | | public void exec(String cmd) { |
| | | try { |
| | | Process process = Runtime.getRuntime().exec(cmd); |
| | | process.waitFor(); |
| | | } catch (Exception ex) { |
| | | logger.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |