Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Redirect/Pipe within a VBscript

96 views
Skip to first unread message

Terry Glass

unread,
Jan 6, 2008, 10:35:00 PM1/6/08
to
Brand new to scripting. Having a problem getting a redirect or pipe command
to work within a VBscript, have been working on this for 2 weeks and have
tried a multitude of different solutions.

The script runs a Microsoft tool called psexec which I use to connect to a
remote Cisco CallManager server running Windows 2000 Server. It then runs a
command called mmfspy.exe with an argument, in this case i. The results of
'mmfspy i' is redirected to a text file on my Windows 2000 Pro workstation.

If I just open a command prompt on my workstation and run 'C:\PsTools\psexec
\\192.168.160.129 -u ccmpub\administrator -p cisco mmfspy i>c:\test.txt' ,
everything works fine.

When I try to call the same command using a vbscrip on my workstation,
everything runs BUT the text file is not created. The piping is not working
when run inside a script. I can not figure out how to make this pipe command
work. Can anyone correct my code and show me what I am doing wrong?

My Complete Code:

Dim objNetwork

Set objNetwork = Wscript.CreateObject("Wscript.Network")
Set objShell = WScript.CreateObject("WScript.Shell")


objShell.Run "C:\PsTools\psexec \\192.168.160.129 -u ccmpub\administrator
-p cisco mmfspy i>c:\test.txt"

Trevor Sullivan

unread,
Jan 7, 2008, 4:30:37 AM1/7/08
to
Terry,

It depends on the folder context in which your script is running. I
would assume that it would output the file in the folder your script is
running in, but I don't use this syntax normally, and couldn't tell you
for sure.

What I would recommend doing is the following:

Rather than using the WshShell Run method, I would suggest calling the
Exec method. This is well-documented on MSDN, and gives you direct
access to the StdIn, StdOut, and StdErr streams. When you call the Exec
method, you will be returned a WshShellExec object, which contains
several properties pointing to the respective streams. These properties
each return a stream object that allows you to read or write to the
stream. Actually, I just found a great article on it here:

http://www.microsoft.com/technet/scriptcenter/resources/tales/sg1002.mspx

-----------------------------------------------------------------

Also, just so you're aware, since you're new to scripting, and although
I would NOT recommend using it for this particular case, you can use WMI
to spawn a process. The Win32_Process class beneath the root\cimv2
namespace has a "Create" method that takes a string parameter, which
would contain the command you want to run. This is really handy for when
you want to spawn a process on a system remotely, but I don't believe
that it gives you access to any of the I/O streams that you need for
this scenario.

Hope this helps,

-----------------
Trevor Sullivan
Systems Engineer

ekkehard.horner

unread,
Jan 7, 2008, 4:43:00 AM1/7/08
to
Terry Glass schrieb:
To use devie rerouting or piping you need a shell, so change

objShell.Run "C:\PsTools\psexec \\192.168.160.129 -u ccmpub\administrator
-p cisco mmfspy i>c:\test.txt"

to

objShell.Run "%comspec% /C C:\PsTools\psexec \\192.168.160.129 -u ccmpub\administrator

Trevor Sullivan

unread,
Jan 7, 2008, 4:55:43 AM1/7/08
to
That looks like a proper explanation :) If you need access the the
pipeline -inside- your script, however, you're still going to need the
WshShellExec object, I believe.

----------------
Trevor Sullivan
Systems Engineer

0 new messages