I have a problem trying to run a DOS cmd and redirect the output to a text
file.
The code below only works as far as the Messages Boxes display the correct
information, ie. the paths are correct,
but not test.txt file is being created!

The purpose is to catch the output from a reverse DNS Lookup tool
"zwhois.exe.
Eventually, I want to run this code from either a VBS file or a web page,
and display the result on screen, rather than having to run the cmd from a
DOS prompt

The DOS exe file can be downloaded from here:
http://www.zoneedit.com/doc/code/zwhois.exe

' whois.vbs which resides in the same folder as the exe file

Dim objWHShell
Dim scriptPath
Dim exeFile
Dim txtFile
Dim Cmd

' scriptPath is returned with a "\" appended at the end
scriptPath = Left(WScript.ScriptFullName,Len(Wscript.ScriptFullName) -
Len(Wscript.ScriptName))

exeFile = scriptPath & "zwhois.exe -v 217.233.242.39 >> " ' -v = verbose
followed by the IP to query
txtFile =scriptPath & "test.txt"
Cmd = exeFile & txtFile

' MsgBox exeFile
' MsgBox txtFile
' MsgBox Cmd

RunFile Cmd

Sub RunFile(CmdToRun)
On Error Resume Next
Set objWHShell = CreateObject("Wscript.Shell")
objWHShell.Run Chr(34) & CmdToRun & Chr(34)
Set objWHShell = Nothing
End Sub

--
Many Thanks in advance guys

Joseph

philippeoget at hotmail dot com
http://www.geocities.com/philippeoget/a2z/

Re: problem running a dos cmd from a VBS file by Torgeir

Torgeir
Sun Mar 13 11:22:12 CST 2005

Philippe wrote:

> I have a problem trying to run a DOS cmd and redirect the output to a text
> file.
> The code below only works as far as the Messages Boxes display the correct
> information, ie. the paths are correct,
> but not test.txt file is being created!
Hi

Redirecting using < and > (as well as piping using | ) is a function of
cmd.exe, so you need to run your program inside a cmd.exe instance.

Replace
exeFile = scriptPath & "zwhois.exe -v 217.233.242.39 >> "

with
exeFile = "%ComSpec% /c " & scriptPath & "zwhois.exe -v 217.233.242.39 >> "


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx