开发者

Add additional text to end of array element

I am trying to get VBSCript to pass "configure call gcid splitArray(x) delete" for ea开发者_JAVA百科ch element in the array. Instead im getting "configure call gcid splitArray(x)" until the last element which will comeback as "configure call gcid splitArray(x) delete".

I am some what new to scripting, thanks in advance.

<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>

If i use these variables in textarea call1

asd

asd

asd

asd

asd

asd

sad

i will get the following in results textarea

configure call gcid asd

error: Incomplete command. Expected one of: DELETE

deleteconfigure call gcid asd

error: invalid command name "deleteconfigure"

deleteconfigure call gcid asd error: invalid command name "deleteconfigure"

deleteconfigure call gcid asd

error: invalid command name "deleteconfigure"

deleteconfigure call gcid asd

error: invalid command name "deleteconfigure"

deleteconfigure call gcid asd

error: invalid command name "deleteconfigure"

deleteconfigure call gcid sad delete

error: invalid command name "deleteconfigure"


I think your call2 contains vbCrLfs instead of the vbLf you are splitting for. Evidence:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜