Search code examples
vbscripthp-uft

Wrong Number of Elements for reading from console with UFT


I have the following simple problem with UFT.

My Script is:

Dim testShell
Set testShell = CreateObject ("wscript.shell")
testShell.exec "cmd /K CD C:\ & Dir"
msgbox(testShell.Exec.StdOut)

Which gives me the following error:

Wrong number of Arguments : 'testShell.exec' Line (4): "msgbox(testShell.Exec.StdOut)".

I have looked at several VbScripts so far and there it seems to work with no problems. Why does my script fail? I am very sure it is something very stupid and simple, but i cannot see my error. I just want to get the output of my shell into a variable so i can work with it.


Solution

  • You need the object returned by .Exec to get the .StdOut and its content and /K should be /C:

    >> Set testShell = CreateObject ("wscript.shell")
    >> Set oExec = testShell.exec("%comspec% /C CD C:\ & Dir")
    >> WScript.Echo oExec.StdOut.ReadAll()
    >>
     Volume in drive C has no label.
     ...
     25.05.2011  19:32    <DIR>          apache-ant-1.8.2
     ...