| | |
| | | <relativePath/> |
| | | </parent> |
| | | <!--打包成jar、war--> |
| | | <packaging>jar</packaging> |
| | | <packaging>war</packaging> |
| | | |
| | | <groupId>com</groupId> |
| | | <artifactId>yssh</artifactId> |
| | |
| | | <artifactId>spring-boot-starter-web</artifactId> |
| | | <!--排除内置tomcat容器,让外部容器运行spring-boot项目--> |
| | | <exclusions> |
| | | <!--<exclusion> |
| | | <exclusion> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-tomcat</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <exclusion> |
| | | <groupId>org.apache.logging.log4j</groupId> |
| | | <artifactId>log4j-api</artifactId> |
| | | </exclusion>--> |
| | | </exclusion><!----> |
| | | </exclusions> |
| | | </dependency> |
| | | <!--spring事务管理--> |
| | |
| | | @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); |
| | | } |
| | | } |
| | | } |
| | |
| | | socket: |
| | | ip: 127.0.0.1 |
| | | port: 6666 |
| | | |
| | | cmd: |
| | | runPy: C:/Python310/py/runPy.bat |