Running shell command and recording output 
Author Message
 Running shell command and recording output

Any idea how I can run a shell command and record the output for use later?
I have tried using the WSH shell run command with the command piping out to
a text file, but this does not seem to work

Background
========
I am trying to write a script that lets me input a start IP address and an
end IP address and ping everything between.

The script I have thus far is:

Option Explicit
Dim FSO, WSHShell, IPSubnet, IPStart, IPEnd, f, i, cmdPing, my_RETURN

Set FSO = CreateObject("Scripting.FileSystemObject")
set WSHShell=Wscript.CreateObject("Wscript.Shell")
IPSubnet = InputBox("Enter first three octets of IP range, e.g.
165.244.217")
IPStart = InputBox("Enter First IP Address in range","IP Start")
IPEnd =  InputBox("Enter Last IP Address in range","IP End")

set f = FSO.CreateTextFile("c:\ping.txt", TRUE)
f.WriteLine("Results of ping for IP range " & IPSubnet _
     & "." & IPStart & " to " & IPSubnet & "." & IPEnd)
f.Close

'Ping through IP Addresses and return results

For i = IPStart to IPEnd
    cmdPing = "ping -a -n 1 "& IPSubnet & "." & i & " >> c:\ping.txt"
    my_Return =  WSHShell.Run(cmdPing ,1, TRUE)
NEXT

Thanks in advance

Mark Salter
LG Electronics Wales



Fri, 27 Dec 2002 03:00:00 GMT  
 Running shell command and recording output

Quote:

> Any idea how I can run a shell command and record the output for use later?
> I have tried using the WSH shell run command with the command piping out to
> a text file, but this does not seem to work

> Background
> ========
> I am trying to write a script that lets me input a start IP address and an
> end IP address and ping everything between.

> The script I have thus far is:

> Option Explicit
> Dim FSO, WSHShell, IPSubnet, IPStart, IPEnd, f, i, cmdPing, my_RETURN

> Set FSO = CreateObject("Scripting.FileSystemObject")
> set WSHShell=Wscript.CreateObject("Wscript.Shell")
> IPSubnet = InputBox("Enter first three octets of IP range, e.g.
> 165.244.217")
> IPStart = InputBox("Enter First IP Address in range","IP Start")
> IPEnd =  InputBox("Enter Last IP Address in range","IP End")

> set f = FSO.CreateTextFile("c:\ping.txt", TRUE)
> f.WriteLine("Results of ping for IP range " & IPSubnet _
>      & "." & IPStart & " to " & IPSubnet & "." & IPEnd)
> f.Close

> 'Ping through IP Addresses and return results

> For i = IPStart to IPEnd
>     cmdPing = "ping -a -n 1 "& IPSubnet & "." & i & " >> c:\ping.txt"
>     my_Return =  WSHShell.Run(cmdPing ,1, TRUE)
> NEXT

> Thanks in advance

> Mark Salter
> LG Electronics Wales


A common problem.  'Redirecting' output in a console session requires
the system's command processor, because it is not supported by the Run
method's code.

Try this ..

    my_Return =  WSHShell.Run("%comspec% /c " & cmdPing , 0, TRUE)

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Fri, 27 Dec 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. redirect output of program run with shell command

2. Run a DOS command and Get output of a DOS command in VB5

3. Direct VB Shell command output to a file

4. Capturing Output from shell command to VB

5. VB4 - problem creating text from redirected output of shell command

6. Capture all shell command output?

7. capturing a shell commands output

8. Help !! display output from shell command constantly

9. Sending shell command output to file

10. Capturing output from Shell.run

11. Specify working directory for shell.run command?

12. Running DOS Shell in hidden window, or using vb command instead

 

 
Powered by phpBB® Forum Software