0

I am trying to run the following command and return the output of it using VBscript:

dir /A-d "C:\Windows\Minidump" | find /c "/"

And I have the following script but it does not work (probably because of " charachters:

Wscript.Echo runCMD("dir /A-d "C:\Windows\Minidump" | find /c "/"")

Function runCMD(strRunCmd)

 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objExec = objShell.Exec(strRunCmd)

 strOut = ""

 Do While Not objExec.StdOut.AtEndOfStream
  strOut = strOut & objExec.StdOut.ReadLine()
 Loop

 Set objShell = Nothing
 Set objExec = Nothing

 runCMD = strOut

End Function

Any suggestions on how to achieve this?

1
  • Does it have to be vbscript? could you just place the following in a bat file? dir /A-d "C:\Windows\Minidump" | find /c "/" > newfile.txt Commented Jan 22, 2015 at 12:04

1 Answer 1

3
  1. dir is intrinsic; you need %comspec%.
  2. Double quotes need to be escaped by double double quotes in VBScript:

    Wscript.Echo runCMD("%comspec% /c dir /A-d ""C:\Windows\Minidump"" | find /c ""/""")
    
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.