WScript.Shell echo command?


  1.    03 Jan 2009 #1
    ryan Guest

    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

  2.    03 Jan 2009 #2
    Pegasus \(MVP\) Guest

    Re: WScript.Shell echo command?



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

    > 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

  3.    03 Jan 2009 #3
    Ruediger Roesler Guest

    Re: WScript.Shell echo command?


    ryan@xxxxxx <ryan@xxxxxx> typed:

    > 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

  4.    03 Jan 2009 #4
    Richard Mueller [MVP] Guest

    Re: WScript.Shell echo command?



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

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

    >> 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

  5.    04 Jan 2009 #5
    Tom Lavedas Guest

    Re: WScript.Shell echo command?


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

    > 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

  6.    04 Jan 2009 #6
    mayayana Guest

    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.

    > ----------------------------------------
    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

WScript.Shell echo command?

Similar Threads
Thread Forum
Problem with wscript.shell run and MS Office files
My work setup is Vista Enterprise 32 bit with SP1 and Office 2007 and IE7. I am writing a browser based application using Visual Studio 2008. ...
Software
wscript.run <command with spaces in path>
Hi, I'm trying to do something like: set wshShell = wscript.createObject"wscript.shell") wshShell.Run("C:\Program Files\TightVNC\unis000.exe") ...
VB Script
Wscript.Shell open file in wmplayer
I'm making an app that lives on a CD that opens wmv's from the CD. I thought everything was going well until I realized that if wmplayer isn't the...
VB Script
wscript.echo only a new line / embed a "CR" in a text string ?
How can I output a simple new line CR in an existing wscript.echo command? Ok, I could write: wscript.echo "my output text" wscript.echo ...
VB Script
WScript.Shell -> Terminal Server 2008...
Hi guys! OS: MS terminal server 2008 user rights: remote desktop user / domain user I have a question, which is related to the command "Set...
VB Script
WScript.Echo
If I use WScript.Echo "Working" The script will not run until the user click the OK button. Any way around this?
VB Script
Powershell starts but never exits when invoked from Wscript shell
Hi, I am trying to invoke a very basic powershell command (version 1.0) from a .js script, via a Wscript shell (using the exec() command of...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 02:24.
    .