亚行外壳和红宝石
问题描述:
试图写一个小红宝石脚本来自动化一些繁琐的东西,我目前在Windows命令提示符手动。亚行外壳和红宝石
伪代码:
系统 “ADB杀服务器”
系统 “亚行启动服务器”
系统 “亚行连接192.168.xxx.xxx”
系统“ADB外壳“
这是我卡住的地方。
在亚行的shell提示符下,我想:
cd到/一些/目录
RM一堆文件
在我的Ruby脚本的,我怎么插入的cd命令adb shell提示符? 然后在adb shell提示符处插入rm命令。
我试过“系统”没有效果。我假设“系统”只能用于与Windows命令提示符通信,而不是adb shell?
任何帮助将不胜感激。 谢谢。
答
尝试以下
#!/usr/bin/env ruby
#
require 'pty'
require 'expect'
system "adb kill-server"
system "adb start-server"
system "adb connect 192.168.xxx.xxx"
PTY.spawn("adb shell") do |output, input, process_id|
input.puts("cd /to/some/directory")
input.puts("rm a-bunch-of-files")
input.puts("exit")
end
答
代码user1835175的PTY的建议是巨大的,如果它有一个工作窗口等效。在ConEmu Bash控制台的Windows7/Ruby 2.3.0下试过rubysl-pty,但没有奏效,你可以提出一个新的问题如何在Windows中安装它。
我做了类似于您在另一个使用Autoit的终端中所要求的内容。 它有它自己的脚本语言,但你也可以从Ruby使用它。
你可以使用它在Ruby中像下面,(也可以是简单的,但我需要鼠标控制研究也),看其他的例子,但是这是为我工作的代码..
require 'win32ole'
# AutoIt3 needs to be installed
app = "Adb"
appClass = "[CLASS:SunAwtFrame]" # retrieved with AutoIt Window Info
ai = WIN32OLE.new("AutoItX3.Control")
ai.WinActivate(appClass)
handle = "[HANDLE:#{ai.wingethandle(appClass)}]"
ai.Opt("MouseCoordMode", 0)
ai.Opt("WinTitleMatchMode", 4)
ai.Send('cd \somefolder')
ai.Send('{ENTER}')
...
PTY没有按”在windows下工作,rubysl-pty用于Ruby 1.9.3,但不是2.3.0 – peter