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 - WScript.Shell echo command?

Reply
 
Old 01-03-2009   #1 (permalink)
ryan


 
 

WScript.Shell echo command?

I'm trying to run a program within vbs using WScript.Shell that
requires a pipe. The command i need to run is

echo <text> | clip

But when i run the following as a test i get WshShell.Exec: The system
cannot find the file specified.

sCmd = "echo test | clip"
Set oShell = CreateObject("WScript.Shell")
Set oExCmd = oShell.Exec(sCmd)

How can i use the echo command or another command to pipe text into
the another program?

My System SpecsSystem Spec
Old 01-03-2009   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: WScript.Shell echo command?


<ryan@xxxxxx> wrote in message
news:9b701477-e182-44c1-8792-91877ef30fe4@xxxxxx
Quote:

> I'm trying to run a program within vbs using WScript.Shell that
> requires a pipe. The command i need to run is
>
> echo <text> | clip
>
> But when i run the following as a test i get WshShell.Exec: The system
> cannot find the file specified.
>
> sCmd = "echo test | clip"
> Set oShell = CreateObject("WScript.Shell")
> Set oExCmd = oShell.Exec(sCmd)
>
> How can i use the echo command or another command to pipe text into
> the another program?
"echo" is an internal Command Processor command, same as "cd" or "copy". To
invoke it from another program you need to invoke it through the Command
Processor like so:

cmd.exe /c echo Hello World or
%comspec" /c echo Hello World

A much simpler method would be to echo the desired string directly from
within VB Script instead of shelling out to to Command Processor, by using
this code:

wscript.echo "Hello World"


My System SpecsSystem Spec
Old 01-03-2009   #3 (permalink)
Ruediger Roesler


 
 

Re: WScript.Shell echo command?

ryan@xxxxxx <ryan@xxxxxx> typed:
Quote:

> I'm trying to run a program within vbs using WScript.Shell that
> requires a pipe. The command i need to run is
>
> echo <text> | clip
>
> But when i run the following as a test i get WshShell.Exec: The system
> cannot find the file specified.
>
> sCmd = "echo test | clip"
> Set oShell = CreateObject("WScript.Shell")
> Set oExCmd = oShell.Exec(sCmd)
>
> How can i use the echo command or another command to pipe text into
> the another program?
This example 'ReadOutput.vbs' demonstrates catching the output of a
process at the command-line:

Dim wshShell, wshExec, strResult

Set wshShell = CreateObject("WScript.Shell")

strObjekt = """svchost.exe"""
strCmdLine = wshShell.ExpandEnvironmentStrings("%COMSPEC%")
strCmdLine = strCmdLine & " /c tasklist | find /c " & strObjekt

Set wshExec = wshShell.Exec(strCmdLine)

Do While Not(wshExec.StdOut.AtEndOfStream)
strResult = wshExec.StdOut.ReadLine
Loop

WScript.Echo "There were " & strResult & " processes found of " & _
strObjekt & "."

To execute this example, it requires at least Windows XP Professional
because the program TaskList.exe is not a component of the Home version
of XP.

--
ЯR



My System SpecsSystem Spec
Old 01-03-2009   #4 (permalink)
Richard Mueller [MVP]


 
 

Re: WScript.Shell echo command?


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:uB6naYXbJHA.1328@xxxxxx
Quote:

>
> <ryan@xxxxxx> wrote in message
> news:9b701477-e182-44c1-8792-91877ef30fe4@xxxxxx
Quote:

>> I'm trying to run a program within vbs using WScript.Shell that
>> requires a pipe. The command i need to run is
>>
>> echo <text> | clip
>>
>> But when i run the following as a test i get WshShell.Exec: The system
>> cannot find the file specified.
>>
>> sCmd = "echo test | clip"
>> Set oShell = CreateObject("WScript.Shell")
>> Set oExCmd = oShell.Exec(sCmd)
>>
>> How can i use the echo command or another command to pipe text into
>> the another program?
>
> "echo" is an internal Command Processor command, same as "cd" or "copy".
> To invoke it from another program you need to invoke it through the
> Command Processor like so:
>
> cmd.exe /c echo Hello World or
> %comspec" /c echo Hello World
>
> A much simpler method would be to echo the desired string directly from
> within VB Script instead of shelling out to to Command Processor, by using
> this code:
>
> wscript.echo "Hello World"
I would suggest:
=======
Dim objShell, strCmd, objExecObject, strResults

Set objShell = CreateObject("Wscript.Shell")
strCmd = "%comspec% /c echo test | clip"
Set objExecObject = objShell.Exec(strCmd)
Do Until objExecObject.StdOut.AtEndOfStream
strResults = objExecObject.StdOut.ReadAll
Loop
=====
If the OS is not XP or above you will need to use the Run method of the
wshShell object.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


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


 
 

Re: WScript.Shell echo command?

On Jan 3, 2:12*am, r...@xxxxxx wrote:
Quote:

> I'm trying to run a program within vbs using WScript.Shell that
> requires a pipe. The command i need to run is
>
> echo <text> | clip
>
> But when i run the following as a test i get WshShell.Exec: The system
> cannot find the file specified.
>
> sCmd = "echo test | clip"
> Set oShell = CreateObject("WScript.Shell")
> Set oExCmd = oShell.Exec(sCmd)
>
> How can i use the echo command or another command to pipe text into
> the another program?
Beside the approach you have chosen, there is this one that works in
script using IE ...

putClipBoardText4 InputBox("Enter some text", "Test Clip Write/Read")
wsh.sleep 50
wsh.echo GetClipBoardText4

' Requires IE v5.0+
Function getClipBoardText5()
With CreateObject("htmlfile")
On Error Resume Next
getClipBoardText5 = .ParentWindow.ClipboardData.GetData("text")
end with ' htmlfile
End Function

' Requires IE v5.0+
sub putClipBoardText5(sText)
With CreateObject("InternetExplorer.Application")
.Navigate "about:blank"
Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
.document.ParentWindow.ClipboardData.SetData "text", sText
end with ' IE
End Sub

IE 7 protests and requires a security change to use the clipboard.
Unfortunately, I can't remember now what the proper setting is. I
still try to avoid IE 7 and my work IT group forbids it.

Tom Lavedas
=========
My System SpecsSystem Spec
Old 01-04-2009   #6 (permalink)
mayayana


 
 

Re: WScript.Shell echo command?

I think it actually requires so-called IE 5.01
to run your sample. (Also, there's a minor
typo. with GetClipBoardText4.) I'm not sure what
the problem is, but I think that part of the DOM
just wasn't finished in IE 5.0. The objects and methods
are there and don't cause any errors. But GetData
always comes back empty and SetData has no effect.

So it's limited to Windows 2000/ME/XP. Win98SE
had IE 5.00.2614. Anything higher than 5.00.26xx
is called "IE 5.01", which came in with Win2000. Yet
although there were a number of versions of 5.00.26xx+,
there was never actually any version numbered 5.01.xxxx!
It jumped to 5.5 in WinME. That numbering pattern is all
the more strange given that Win2000's 5.00.29xx+ seemed
to have been a fairly major update. So they made a major
update with a minor build number change, and then
referred to it by a different version number -- 5.01 --
as though it were numbered with a minor *version* number
change.
I think of "5.01", 5.5 and 6 all being pretty much the same
thing. I'm not sure how accurate that perception is in terms of
HTML rendering because I've never used 5.01 and rarely
used 5.5, but in terms of bugs and vulnerabilities it
seemed that 5.01 -> 6 had about the same ones, while
IE5 was not vulnerable to some of those.
Quote:

> ----------------------------------------
putClipBoardText4 InputBox("Enter some text", "Test Clip Write/Read")
wsh.sleep 50
wsh.echo GetClipBoardText4

' Requires IE v5.0+
Function getClipBoardText5()
With CreateObject("htmlfile")
On Error Resume Next
getClipBoardText5 = .ParentWindow.ClipboardData.GetData("text")
end with ' htmlfile
End Function

' Requires IE v5.0+
sub putClipBoardText5(sText)
With CreateObject("InternetExplorer.Application")
.Navigate "about:blank"
Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
.document.ParentWindow.ClipboardData.SetData "text", sText
end with ' IE
End Sub

IE 7 protests and requires a security change to use the clipboard.
Unfortunately, I can't remember now what the proper setting is. I
still try to avoid IE 7 and my work IT group forbids it.

Tom Lavedas
=========


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
wscript.echo only a new line / embed a "CR" in a text string ? VB Script
WScript.Shell -> Terminal Server 2008... VB Script
echo out interactive parameters that were entered for a command PowerShell
WScript.Echo VB Script
Powershell starts but never exits when invoked from Wscript shell PowerShell


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