2014-09-21 61 views
0

我從一個.bat腳本調用7個vbscripts來啓動7個Android模擬器的Telnet會話。問題是最後所有的vbscript都會寫入同一個Telnet會話。我對腳本很陌生,所以請幫忙。與vbscript並行運行多個Telnet會話

begin.bat

setlocal enabledelayedexpansion 

FOR /L %%G IN (1,1,7) DO (
    ::start emulator 
    emulator -avd em%%G 
    :: Open a Telnet window 
    timeout /t 60 /nobreak >NUL 

    set /A "_myport= 5552+2*%%G" 
    timeout /t 1 /nobreak >NUL 
    telnet.exe localhost !_myport! 
    ::run script 
    cscript SendKeys.vbs) 

SendKeys.vbs

set OBJECT=WScript.CreateObject("WScript.Shell") 
WScript.sleep 50 

Dim max,min 
max=100 
min=1 
Randomize 
battery_level= Int((max-min+1)*Rnd+min) 

OBJECT.SendKeys "power capacity " 
OBJECT.SendKeys battery_level 
OBJECT.SendKeys "{ENTER}" 



'Xml stuff for getting the coordinates 
Set objXML = CreateObject("Microsoft.XMLDOM") 

objXML.async = False 
objXML.Load ("C:\Users\basilhs\Downloads\alimos-omonoia.xml") 




Set point = objXML.getElementsByTagName("trkpt") 

For i = 0 To point.length - 1 
    Set subNodes = point(i) 
    OBJECT.SendKeys "geo fix " 
    OBJECT.SendKeys subNodes.getAttribute("lon") 
    OBJECT.SendKeys " " 
    OBJECT.SendKeys subNodes.getAttribute("lat") 
    OBJECT.SendKeys "{ENTER}" 
    WScript.Sleep 5000 
Next 
    OBJECT.SendKeys "exit{ENTER}" 
+1

它永遠不會讓我感到驚訝,人們會如何採取笨拙的'SendKeys'方法來編寫'telnet'而不是使用['telnet'](http://www.chiark.greenend.org.uk/)。 〜sgtatham/putty/download.html)這實際上是腳本化的... – 2014-09-21 21:35:41

+0

感謝您的回覆,但您可以更具體請,我是新手腳本。 – ecespecial 2014-09-22 09:32:39

回答

0

查找AppActivate

set WshShell = WScript.CreateObject("WScript.Shell") 

     WshShell.Run "calc" 
     WshShell.Run "notepad" 

     WScript.Sleep 100 

     Msgbox WshShell.AppActivate("Save As") 

     WScript.Sleep 100 

     Msgbox WshShell.AppActivate("Calculator") 

     WScript.Sleep 100 
     Msgbox WshShell.AppActivate("Notepad") 

     WScript.Sleep 100 
     Msgbox WshShell.AppActivate("Calculator") 

     WScript.Sleep 100 

和這裏的另一個樣本

set WshShell = WScript.CreateObject("WScript.Shell") 

If WSHShell.AppActivate("Calculator")=False then 
    WshShell.Run "C:\windows\System32\calc.exe", 1, false 
End If