ruby linux连接windows执行dos命令

在整个开发流程中,gitlab-runner-ci是搭建在linux下。web自动化是在windows下面进行的。

如果ci构建完版本、部署完后,需要触发启动自动化执行。

那么我们需要在部署完后在linux下再调用win下自动化启动脚本。这样就做到提交代码后,编译、单元测试、覆盖率、打包、系统测试无人干预的全自动化处理。

1、启用win下telnet服务。(开启方法略)

2、使用ruby net-telnet包实现如下:  

require 'net/telnet'
localhost = '172.17.x.xx'
userName = 'shenxxxxxx'
passWD = 'shenxxxxxx'

host = Net::Telnet::new(
         "Host"       => localhost,
         "Prompt"=> /C:.*>/)

host.login(userName, passWD) { |c| print c }
host.cmd("dir") { |c| print c }
host.close

 

执行结果如下:

image

posted @ 2017-03-31 11:34  Fithon  阅读(403)  评论(0编辑  收藏  举报