Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Passing "| find" in command executed with EXEC method does not work

Reply
 
Old 08-04-2009   #1 (permalink)
Steve


 
 

Passing "| find" in command executed with EXEC method does not work

If I try to pass "| find" command with psinfo, executed with the EXEC
method I get a syntax error from psinfo. If I take the EXACT command
and run it at the command prompt it works fine. Any thoughts on why
this does not work?

---------------begin code------------------
compName = "SERVER1"
var1 = "c:\catapult\pstools\psinfo applications -s \\" & compName & "
| find /V " & chr(34) & "Security Update" & chr(34) & " | find /V " &
chr(34) & "Update for Windows" & chr(34) & " | find /V " & chr(34) &
"Hotfix" & chr(34)
msgbox var1
var2 = ExecCmd(var1)
wscript.echo var2

Function ExecCmd(Command)
Dim oExec,WshShell, Line

Set WshShell = WScript.CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(Command)
Line = ""
Do while oExec.Status <> 1
If not oExec.StdOut.AtEndOfStream Then
line = line & oExec.StdOut.ReadAll
End If
If not oExec.StdErr.AtEndOfStream Then
line = line & oExec.StdErr.ReadAll
End If
Loop
ExecCmd = Line
End Function
-------------end code-----------------

Thanks in advance,
Steve

My System SpecsSystem Spec
Old 08-04-2009   #2 (permalink)
Tom Lavedas


 
 

Re: Passing "| find" in command executed with EXEC method does notwork

On Aug 4, 4:18*pm, Steve <collamp...@xxxxxx> wrote:
Quote:

> If I try to pass "| find" command with psinfo, executed with the EXEC
> method I get a syntax error from psinfo. *If I take the EXACT command
> and run it at the command prompt it works fine. *Any thoughts on why
> this does not work?
>
> ---------------begin code------------------
> compName = "SERVER1"
> var1 = "c:\catapult\pstools\psinfo applications -s \\" & compName & "
> | find /V " & chr(34) & "Security Update" & chr(34) & " | find /V " &
> chr(34) & "Update for Windows" *& chr(34) & " | find /V *" & chr(34) &
> "Hotfix" & chr(34)
> msgbox var1
> var2 = ExecCmd(var1)
> wscript.echo var2
>
> Function ExecCmd(Command)
> * * Dim oExec,WshShell, Line
>
> * * * * Set WshShell = WScript.CreateObject("WScript.Shell")
> * * * * Set oExec = WshShell.Exec(Command)
> * * * * Line = ""
> * * * * Do while oExec.Status <> 1
> * * * * * * * * If not oExec.StdOut.AtEndOfStream Then
> * * * * * * * * * * * * line = line & oExec.StdOut.ReadAll
> * * * * * * * * End If
> * * * * * * * * If not oExec.StdErr.AtEndOfStream Then
> * * * * * * * * * * * * line = line & oExec.StdErr.ReadAll
> * * * * * * * * End If
> * * * * Loop
> * * * * ExecCmd = Line
> End Function
> -------------end code-----------------
>
> Thanks in advance,
> Steve
Piping is supported by the command processor, so it needs to be
invoked directly ...

Set oExec = WshShell.Exec("%comsoec /c " &Command)

Tom Lavedas
***********
My System SpecsSystem Spec
Old 08-04-2009   #3 (permalink)
Steve


 
 

Re: Passing "| find" in command executed with EXEC method does notwork

On Aug 4, 4:37*pm, Tom Lavedas <tglba...@xxxxxx> wrote:
Quote:

> On Aug 4, 4:18*pm, Steve <collamp...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > If I try to pass "| find" command with psinfo, executed with the EXEC
> > method I get a syntax error from psinfo. *If I take the EXACT command
> > and run it at the command prompt it works fine. *Any thoughts on why
> > this does not work?
>
Quote:

> > ---------------begin code------------------
> > compName = "SERVER1"
> > var1 = "c:\catapult\pstools\psinfo applications -s \\" & compName & "
> > | find /V " & chr(34) & "Security Update" & chr(34) & " | find /V " &
> > chr(34) & "Update for Windows" *& chr(34) & " | find /V *" & chr(34) &
> > "Hotfix" & chr(34)
> > msgbox var1
> > var2 = ExecCmd(var1)
> > wscript.echo var2
>
Quote:

> > Function ExecCmd(Command)
> > * * Dim oExec,WshShell, Line
>
Quote:

> > * * * * Set WshShell = WScript.CreateObject("WScript.Shell")
> > * * * * Set oExec = WshShell.Exec(Command)
> > * * * * Line = ""
> > * * * * Do while oExec.Status <> 1
> > * * * * * * * * If not oExec.StdOut.AtEndOfStream Then
> > * * * * * * * * * * * * line = line & oExec.StdOut.ReadAll
> > * * * * * * * * End If
> > * * * * * * * * If not oExec.StdErr.AtEndOfStream Then
> > * * * * * * * * * * * * line = line & oExec.StdErr.ReadAll
> > * * * * * * * * End If
> > * * * * Loop
> > * * * * ExecCmd = Line
> > End Function
> > -------------end code-----------------
>
Quote:

> > Thanks in advance,
> > Steve
>
> Piping is supported by the command processor, so it needs to be
> invoked directly ...
>
> * * * * Set oExec = WshShell.Exec("%comsoec /c " &Command)
>
> Tom Lavedas
> ***********- Hide quoted text -
>
> - Show quoted text -
Thanks for the reply Tom. Forgive if this is a n00b question, but
what does "%comsoec /c" refer to in your post?

I appreciate your help.

Steve
My System SpecsSystem Spec
Old 08-04-2009   #4 (permalink)
Pegasus [MVP]


 
 

Re: Passing "| find" in command executed with EXEC method does not work


"Steve" <collampton@xxxxxx> wrote in message
news:9c0ac0ef-217b-4831-b1da-e6f1ecf9bfde@xxxxxx
Quote:

> If I try to pass "| find" command with psinfo, executed with the EXEC
> method I get a syntax error from psinfo. If I take the EXACT command
> and run it at the command prompt it works fine. Any thoughts on why
> this does not work?
>
> ---------------begin code------------------
> compName = "SERVER1"
> var1 = "c:\catapult\pstools\psinfo applications -s \\" & compName & "
> | find /V " & chr(34) & "Security Update" & chr(34) & " | find /V " &
> chr(34) & "Update for Windows" & chr(34) & " | find /V " & chr(34) &
> "Hotfix" & chr(34)
> msgbox var1
> var2 = ExecCmd(var1)
> wscript.echo var2
>
> Function ExecCmd(Command)
> Dim oExec,WshShell, Line
>
> Set WshShell = WScript.CreateObject("WScript.Shell")
> Set oExec = WshShell.Exec(Command)
> Line = ""
> Do while oExec.Status <> 1
> If not oExec.StdOut.AtEndOfStream Then
> line = line & oExec.StdOut.ReadAll
> End If
> If not oExec.StdErr.AtEndOfStream Then
> line = line & oExec.StdErr.ReadAll
> End If
> Loop
> ExecCmd = Line
> End Function
> -------------end code-----------------
>
> Thanks in advance,
> Steve
Further to Tom's reply: Running a VB Script program and invoking find.exe
three times is not "nice". VB Script has its own "find" function (instr),
and using it would not only avoid your three pipes but it would also speed
up your script enormously. This may not matter much in this particular case
but it does when you invoke find.exe many times.


My System SpecsSystem Spec
Old 08-04-2009   #5 (permalink)
Tom Lavedas


 
 

Re: Passing "| find" in command executed with EXEC method does notwork

On Aug 4, 5:43*pm, Steve <collamp...@xxxxxx> wrote:
Quote:

> On Aug 4, 4:37*pm, Tom Lavedas <tglba...@xxxxxx> wrote:
>
>
>
Quote:

> > On Aug 4, 4:18*pm, Steve <collamp...@xxxxxx> wrote:
>
Quote:
Quote:

> > > If I try to pass "| find" command with psinfo, executed with the EXEC
> > > method I get a syntax error from psinfo. *If I take the EXACT command
> > > and run it at the command prompt it works fine. *Any thoughts on why
> > > this does not work?
>
Quote:
Quote:

> > > ---------------begin code------------------
> > > compName = "SERVER1"
> > > var1 = "c:\catapult\pstools\psinfo applications -s \\" & compName &"
> > > | find /V " & chr(34) & "Security Update" & chr(34) & " | find /V " &
> > > chr(34) & "Update for Windows" *& chr(34) & " | find /V *" & chr(34) &
> > > "Hotfix" & chr(34)
> > > msgbox var1
> > > var2 = ExecCmd(var1)
> > > wscript.echo var2
>
Quote:
Quote:

> > > Function ExecCmd(Command)
> > > * * Dim oExec,WshShell, Line
>
Quote:
Quote:

> > > * * * * Set WshShell = WScript.CreateObject("WScript.Shell")
> > > * * * * Set oExec = WshShell.Exec(Command)
> > > * * * * Line = ""
> > > * * * * Do while oExec.Status <> 1
> > > * * * * * * * * If not oExec.StdOut.AtEndOfStream Then
> > > * * * * * * * * * * * * line = line & oExec..StdOut.ReadAll
> > > * * * * * * * * End If
> > > * * * * * * * * If not oExec.StdErr.AtEndOfStream Then
> > > * * * * * * * * * * * * line = line & oExec..StdErr.ReadAll
> > > * * * * * * * * End If
> > > * * * * Loop
> > > * * * * ExecCmd = Line
> > > End Function
> > > -------------end code-----------------
>
Quote:
Quote:

> > > Thanks in advance,
> > > Steve
>
Quote:

> > Piping is supported by the command processor, so it needs to be
> > invoked directly ...
>
Quote:

> > * * * * Set oExec = WshShell.Exec("%comsoec /c " &Command)
>
Quote:

> > Tom Lavedas
> > ***********- Hide quoted text -
>
Quote:

> > - Show quoted text -
>
> Thanks for the reply Tom. *Forgive if this is a n00b question, but
> what does "%comsoec /c" refer to in your post?
>
> I appreciate your help.
>
> Steve
Well, first I need to apologize. I was in a hurry and introduced two
errors into what I typed. It should not be "%comsoec /c ", but rather
"%comspec% /c ". Sorry for any confusion I caused by my haste.

That is the environment variable generated by the system to point to
the correct location for the command processor - usually cmd.exe,
these days. If you drop to a command prompt and type SET COMS followed
by the Enter key, you will see what is stored in the variable. It is
almost always C:\Windows\system32\cmd.exe, but it doesn't have to be.
For example, I have an upgraded Win2K machine at home that returns C:
\WinNT\system32\cmd.exe. Still, if the PATH statement points to the
%SystemRoot%\system32 location, a simple call to CMD.EXE will
suffice. I make it a habit to use the COMSPEC variable just to be
that much more certain I get the result I expect.

Tom Lavedas
***********
My System SpecsSystem Spec
Old 08-04-2009   #6 (permalink)
Steve


 
 

Re: Passing "| find" in command executed with EXEC method does notwork

On Aug 4, 4:49*pm, "Pegasus [MVP]" <n...@xxxxxx> wrote:
Quote:

> "Steve" <collamp...@xxxxxx> wrote in message
>
> news:9c0ac0ef-217b-4831-b1da-e6f1ecf9bfde@xxxxxx
>
>
>
>
>
Quote:

> > If I try to pass "| find" command with psinfo, executed with the EXEC
> > method I get a syntax error from psinfo. *If I take the EXACT command
> > and run it at the command prompt it works fine. *Any thoughts on why
> > this does not work?
>
Quote:

> > ---------------begin code------------------
> > compName = "SERVER1"
> > var1 = "c:\catapult\pstools\psinfo applications -s \\" & compName & "
> > | find /V " & chr(34) & "Security Update" & chr(34) & " | find /V " &
> > chr(34) & "Update for Windows" *& chr(34) & " | find /V *" & chr(34) &
> > "Hotfix" & chr(34)
> > msgbox var1
> > var2 = ExecCmd(var1)
> > wscript.echo var2
>
Quote:

> > Function ExecCmd(Command)
> > * *Dim oExec,WshShell, Line
>
Quote:

> > Set WshShell = WScript.CreateObject("WScript.Shell")
> > Set oExec = WshShell.Exec(Command)
> > Line = ""
> > Do while oExec.Status <> 1
> > If not oExec.StdOut.AtEndOfStream Then
> > line = line & oExec.StdOut.ReadAll
> > End If
> > If not oExec.StdErr.AtEndOfStream Then
> > line = line & oExec.StdErr.ReadAll
> > End If
> > Loop
> > ExecCmd = Line
> > End Function
> > -------------end code-----------------
>
Quote:

> > Thanks in advance,
> > Steve
>
> Further to Tom's reply: Running a VB Script program and invoking find.exe
> three times is not "nice". VB Script has its own "find" function (instr),
> and using it would not only avoid your three pipes but it would also speed
> up your script enormously. This may not matter much in this particular case
> but it does when you invoke find.exe many times.- Hide quoted text -
>
> - Show quoted text -
lol...sometimes it's not easy being a hack.

OK, I will try to rework my approach using a "nicer" method. :-)

Thanks,
Steve

My System SpecsSystem Spec
Old 08-04-2009   #7 (permalink)
Steve


 
 

Re: Passing "| find" in command executed with EXEC method does notwork

On Aug 4, 4:59*pm, Tom Lavedas <tglba...@xxxxxx> wrote:
Quote:

> On Aug 4, 5:43*pm, Steve <collamp...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > On Aug 4, 4:37*pm, Tom Lavedas <tglba...@xxxxxx> wrote:
>
Quote:
Quote:

> > > On Aug 4, 4:18*pm, Steve <collamp...@xxxxxx> wrote:
>
Quote:
Quote:

> > > > If I try to pass "| find" command with psinfo, executed with the EXEC
> > > > method I get a syntax error from psinfo. *If I take the EXACT command
> > > > and run it at the command prompt it works fine. *Any thoughts on why
> > > > this does not work?
>
Quote:
Quote:

> > > > ---------------begin code------------------
> > > > compName = "SERVER1"
> > > > var1 = "c:\catapult\pstools\psinfo applications -s \\" & compName& "
> > > > | find /V " & chr(34) & "Security Update" & chr(34) & " | find /V "&
> > > > chr(34) & "Update for Windows" *& chr(34) & " | find /V *" & chr(34) &
> > > > "Hotfix" & chr(34)
> > > > msgbox var1
> > > > var2 = ExecCmd(var1)
> > > > wscript.echo var2
>
Quote:
Quote:

> > > > Function ExecCmd(Command)
> > > > * * Dim oExec,WshShell, Line
>
Quote:
Quote:

> > > > * * * * Set WshShell = WScript.CreateObject("WScript.Shell")
> > > > * * * * Set oExec = WshShell.Exec(Command)
> > > > * * * * Line = ""
> > > > * * * * Do while oExec.Status <> 1
> > > > * * * * * * * * If not oExec.StdOut.AtEndOfStream Then
> > > > * * * * * * * * * * * * line = line & oExec.StdOut.ReadAll
> > > > * * * * * * * * End If
> > > > * * * * * * * * If not oExec.StdErr.AtEndOfStream Then
> > > > * * * * * * * * * * * * line = line & oExec.StdErr.ReadAll
> > > > * * * * * * * * End If
> > > > * * * * Loop
> > > > * * * * ExecCmd = Line
> > > > End Function
> > > > -------------end code-----------------
>
Quote:
Quote:

> > > > Thanks in advance,
> > > > Steve
>
Quote:
Quote:

> > > Piping is supported by the command processor, so it needs to be
> > > invoked directly ...
>
Quote:
Quote:

> > > * * * * Set oExec = WshShell.Exec("%comsoec /c " &Command)
>
Quote:
Quote:

> > > Tom Lavedas
> > > ***********- Hide quoted text -
>
Quote:
Quote:

> > > - Show quoted text -
>
Quote:

> > Thanks for the reply Tom. *Forgive if this is a n00b question, but
> > what does "%comsoec /c" refer to in your post?
>
Quote:

> > I appreciate your help.
>
Quote:

> > Steve
>
> Well, first I need to apologize. *I was in a hurry and introduced two
> errors into what I typed. *It should not be "%comsoec /c ", but rather
> "%comspec% /c ". *Sorry for any confusion I caused by my haste.
>
> That is the environment variable generated by the system to point to
> the correct location for the command processor - usually cmd.exe,
> these days. If you drop to a command prompt and type SET COMS followed
> by the Enter key, you will see what is stored in the variable. *It is
> almost always C:\Windows\system32\cmd.exe, but it doesn't have to be.
> For example, I have an upgraded Win2K machine at home that returns C:
> \WinNT\system32\cmd.exe. *Still, if the PATH statement points to the
> %SystemRoot%\system32 location, a simple call to CMD.EXE will
> suffice. *I make it a habit to use the COMSPEC variable just to be
> that much more certain I get the result I expect.
>
> Tom Lavedas
> ***********- Hide quoted text -
>
> - Show quoted text -
No problem at all, and thanks so much for the help. This is really
good info!

I've gotten two good pointers so hopefully I can make progress now.

Thanks again,
Steve
My System SpecsSystem Spec
Old 08-05-2009   #8 (permalink)
Steve


 
 

Re: Passing "| find" in command executed with EXEC method does notwork

On Aug 4, 5:02*pm, Steve <collamp...@xxxxxx> wrote:
Quote:

> On Aug 4, 4:59*pm, Tom Lavedas <tglba...@xxxxxx> wrote:
>
>
>
>
>
Quote:

> > On Aug 4, 5:43*pm, Steve <collamp...@xxxxxx> wrote:
>
Quote:
Quote:

> > > On Aug 4, 4:37*pm, Tom Lavedas <tglba...@xxxxxx> wrote:
>
Quote:
Quote:

> > > > On Aug 4, 4:18*pm, Steve <collamp...@xxxxxx> wrote:
>
Quote:
Quote:

> > > > > If I try to pass "| find" command with psinfo, executed with the EXEC
> > > > > method I get a syntax error from psinfo. *If I take the EXACT command
> > > > > and run it at the command prompt it works fine. *Any thoughts on why
> > > > > this does not work?
>
Quote:
Quote:

> > > > > ---------------begin code------------------
> > > > > compName = "SERVER1"
> > > > > var1 = "c:\catapult\pstools\psinfo applications -s \\" & compName & "
> > > > > | find /V " & chr(34) & "Security Update" & chr(34) & " | find /V" &
> > > > > chr(34) & "Update for Windows" *& chr(34) & " | find /V *" & chr(34) &
> > > > > "Hotfix" & chr(34)
> > > > > msgbox var1
> > > > > var2 = ExecCmd(var1)
> > > > > wscript.echo var2
>
Quote:
Quote:

> > > > > Function ExecCmd(Command)
> > > > > * * Dim oExec,WshShell, Line
>
Quote:
Quote:

> > > > > * * * * Set WshShell = WScript.CreateObject("WScript.Shell")
> > > > > * * * * Set oExec = WshShell.Exec(Command)
> > > > > * * * * Line = ""
> > > > > * * * * Do while oExec.Status <> 1
> > > > > * * * * * * * * If not oExec.StdOut.AtEndOfStreamThen
> > > > > * * * * * * * * * * * * line = line & oExec.StdOut.ReadAll
> > > > > * * * * * * * * End If
> > > > > * * * * * * * * If not oExec.StdErr.AtEndOfStreamThen
> > > > > * * * * * * * * * * * * line = line & oExec.StdErr.ReadAll
> > > > > * * * * * * * * End If
> > > > > * * * * Loop
> > > > > * * * * ExecCmd = Line
> > > > > End Function
> > > > > -------------end code-----------------
>
Quote:
Quote:

> > > > > Thanks in advance,
> > > > > Steve
>
Quote:
Quote:

> > > > Piping is supported by the command processor, so it needs to be
> > > > invoked directly ...
>
Quote:
Quote:

> > > > * * * * Set oExec = WshShell.Exec("%comsoec /c " &Command)
>
Quote:
Quote:

> > > > Tom Lavedas
> > > > ***********- Hide quoted text -
>
Quote:
Quote:

> > > > - Show quoted text -
>
Quote:
Quote:

> > > Thanks for the reply Tom. *Forgive if this is a n00b question, but
> > > what does "%comsoec /c" refer to in your post?
>
Quote:
Quote:

> > > I appreciate your help.
>
Quote:
Quote:

> > > Steve
>
Quote:

> > Well, first I need to apologize. *I was in a hurry and introduced two
> > errors into what I typed. *It should not be "%comsoec /c ", but rather
> > "%comspec% /c ". *Sorry for any confusion I caused by my haste.
>
Quote:

> > That is the environment variable generated by the system to point to
> > the correct location for the command processor - usually cmd.exe,
> > these days. If you drop to a command prompt and type SET COMS followed
> > by the Enter key, you will see what is stored in the variable. *It is
> > almost always C:\Windows\system32\cmd.exe, but it doesn't have to be.
> > For example, I have an upgraded Win2K machine at home that returns C:
> > \WinNT\system32\cmd.exe. *Still, if the PATH statement points to the
> > %SystemRoot%\system32 location, a simple call to CMD.EXE will
> > suffice. *I make it a habit to use the COMSPEC variable just to be
> > that much more certain I get the result I expect.
>
Quote:

> > Tom Lavedas
> > ***********- Hide quoted text -
>
Quote:

> > - Show quoted text -
>
> No problem at all, and thanks so much for the help. *This is really
> good info!
>
> I've gotten two good pointers so hopefully I can make progress now.
>
> Thanks again,
> Steve- Hide quoted text -
>
> - Show quoted text -
Thanks again Tom and Pegasus. I used both of your suggestions
("%comspec% /c " in my EXEC statement and nested IF logic with InStr
statements instead of piping to FIND.EXE) and have a faster running,
functional script.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
User executed "System Shutdown (1115)" General Discussion
"Extensible Authentication Protocol" service gives "The system cannot find the file specified" error Vista networking & sharing
Command lines like "http://..." does not work anymore! Vista General
Microsoft exec: Future versions of Windows to be "fundamentally redesigned" Vista General
DOS AUTOEXEC.BAT "PATH" Command Doesn't Work Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46