在VBScript中使用AWK的正确语法是什么?

时间:2012-05-09 17:43:31

标签: vbscript

我有一个VBScript,它可以Telnet到Linux设备,我希望看到可用的内存。以下命令产生“无效的过程调用或参数”错误。

WshShell.SendKeys"df /mnt/cf | awk '/mnt/{print$2}'"

如果我手动telnet到设备并使用相同的命令,这是有效的。有什么建议吗?

到目前为止

代码:

Dim WshShell

Set WshShell = CreateObject("WScript.Shell")
WshShell.run"cmd" 
'*** open command window *** 
WScript.Sleep 250 WshShell.SendKeys("{Enter}") 
WshShell.SendKeys"telnet 10.13.2.2 -f VBSmemSize.txt" 
WshShell.SendKeys("{Enter}") 
WScript.Sleep 2000 
WshShell.SendKeys"root" 
WshShell.SendKeys("{Enter}") 
WScript.Sleep 1500 
WshShell.SendKeys"password" 
WshShell.SendKeys("{Enter}") 
WScript.Sleep 1500 
WshShell.SendKeys"df /mnt/cf |awk '/mnt/{print$2}'" 
WshShell.SendKeys("{Enter}")

2 个答案:

答案 0 :(得分:1)

我对它不太熟悉,但这有用吗:

Dim oShell  

set oShell = wscript.createObject("wscript.shell") 

oShell.Run "df /mnt/cf | awk '/mnt/{print$2}'"

Set oShell = Nothing   

答案 1 :(得分:0)

错误字符为“ {”,这是一个特殊字符。 您可以使用“ {}”将这些特殊字符括起来。 例如,

WshShell.SendKeys"df /mnt/cf |awk '/mnt/{{}print$2{}}'"