在数组元素的末尾添加其他文本

时间:2011-09-14 23:25:19

标签: arrays vbscript

我试图让VBSCript为数组中的每个元素传递“configure call gcid splitArray(x)delete”。相反,我得到“配置调用gcid splitArray(x)”直到最后一个元素将回来作为“configure call gcid splitArray(x)delete”。 我提前做了一些新的脚本编写。

<head>
<title>Test</title>
<HTA:APPLICATION ID="Test"
 APPLICATIONNAME="Test"
 SCROLL="yes"
 SINGLEINSTANCE="yes"
>
</head>
<script language="vbscript">


Sub ClearCalls
  serv2 = editor.serv1.value
  call2 = editor.call1.value
  splitArray = Split(call2, chr(10), -1, 0)
  set Shell = CreateObject("WScript.Shell")
shell.run "cmd.exe"
  Delay 1
Shell.SendKeys "telnet -f c:\results.txt " & serv2 & ".com"
Shell.SendKeys "{ENTER}"
  Delay 1
Shell.SendKeys "username"
Shell.SendKeys "{ENTER}"
Shell.SendKeys "password"
Shell.SendKeys "{ENTER}"
Shell.SendKeys "admin debugsonus"
Shell.SendKeys "{ENTER}"
For x = 0 To UBound(splitArray)
  splitArray1 = "configure call gcid " & splitArray(x) & " delete"
Shell.SendKeys splitArray1
next
Shell.SendKeys "{ENTER}"
  Delay 1
Shell.SendKeys "exit"
Shell.SendKeys "{ENTER}"
  Delay 2
Shell.SendKeys "{ENTER}"
Shell.SendKeys "exit"
Shell.SendKeys "{ENTER}"
readfile
End Sub

Sub Delay( seconds )
  Dim wshShell
  Set wshShell = CreateObject( "WScript.Shell" )
  wshShell.Run "ping -n " & ( seconds + 1 ) & " 127.0.0.1", 0, True
  Set wshShell = Nothing
End Sub

</script>
<script language="JScript" type="text/jscript">
<!--
function readFile()
 {
   var fso, fileHandle, contents, resultvar;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   fileHandle = fso.OpenTextFile(document.editor.resultvar.value, 1);
   contents = fileHandle.ReadAll();
   if (contents)
     document.all("results").value = contents;
   fileHandle.close();
 }
//-->
</script>
<body>
<form name="editor">
<table>
  <tr>
<td align="right">Server Name:</td>
<td><input type="text"  size="18" id="serv1"></td>
  </tr>
  <tr>
<td align="right" valign="top">Calls:</td>
<td><textarea size="18" id="call1" rows="10"></textarea></td>
  </tr>
<td valign="bottom" align="left" colspan="2">
  <button type="submit" name="run_button"  onClick="ClearCalls">Clear Calls</button>
</td>
  <tr>
<td align="right" valign="top">Results:</td>
<td><textarea cols="80" rows="20" name="results" id="results" rows="10"></textarea></td>
  </tr>
</table>
<td><input type="hidden" name="resultvar" value="c:\results.txt"></td>
</body>

如果我在textarea call1中使用这些变量
ASD
ASD
ASD
ASD
ASD
ASD
伤心
我将在结果textarea中得到以下结果
配置调用gcid asd
错误:命令不完整。预期之一:DELETE
deleteconfigure call gcid asd
错误:命令名称无效“deleteconfigure”
deleteconfigure call gcid asd 错误:无效的命令名称“deleteconfigure”
deleteconfigure call gcid asd
错误:命令名称无效“deleteconfigure”
deleteconfigure call gcid asd
错误:命令名称无效“deleteconfigure”
deleteconfigure call gcid asd
错误:命令名称无效“deleteconfigure”
deleteconfigure call gcid sad delete
错误:无效的命令名称“deleteconfigure”

1 个答案:

答案 0 :(得分:2)

我认为您的call2包含vbCrLf而不是您要分割的vbLf。证据:

>> a = Split( Join( Array( "a", "b", "c" ), vbCrLf ), vbLf )
>> For Each s In a
>>     WScript.Echo "xxxx" & s & "yyyy"
>> Next
>>
yyyya
yyyyb
xxxxcyyyy