QTP_QTP操作CMD

来源:互联网 发布:mcmc方法的思想和算法 编辑:程序博客网 时间:2024/06/18 16:57

'运行CMD
SystemUtil.Run "cmd.exe","","C:\WINDOWS\system32","open"
'输入 ping 51testing.com 字段
Window( "object class:=ConsoleWindowClass" ).Type "Ping 51testing.com"
'输入回车
Window( "object class:=ConsoleWindowClass" ).Type micreturn
'获得CMD里面的内容
txt = Window( "object class:=ConsoleWindowClass" ).GetVisibleText()
'在LOG打印出CMD里面的内容
print txt

使用WshShell 对象

Dim wShell, exec
Set wShell = CreateObject( "Wscrīpt.Shell" )
'"%comspec% 是CMD的环境变量名称
Set exec = wShell.Exec( "%comspec% /C ping 51testing.com" )
print exec.StdOut.ReadAll