![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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? 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 Specs![]() |
| | #3 (permalink) |
| | 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? 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 Specs![]() |
| | #4 (permalink) |
| | 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" ======= 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 Specs![]() |
| | #5 (permalink) |
| | 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? 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 Specs![]() |
| | #6 (permalink) |
| | 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: > ---------------------------------------- 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 Specs![]() |
![]() |
| 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 | |||