Write to console in VBScript

Help!!

I have a simple but extreamly frustrating problem.  I have a .vbs file that I am writing to help me debug a web service.  It has a variety of MsgBox statements to show me things I am interested in.

My problem is, I need to pose a question here, and the data being reflected in these baxes is not copy/paste able.  That is all I want to accomplish is to copy what is in the message box.

I tried to write to the console directly, but to no avail.  

       WScript.StdOut.WriteLine " " & responseDocument.xml

Gives me "The handle is invalid.  Code 80070006.  I am new to vbs.  (Give me perl any day.)

Please help me.  I need something quick and effective.  
jflannerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wsteegmansCommented:
You could use the FileSystemObject to write all your data to a textfile. I think this will help ...

Example:

    ' Set up Constants
    Const ForWriting = 2 ' Input OutPut mode
    Const Create = True
   
    Dim MyFile
    Dim FSO ' FileSystemObject
    Dim TSO ' TextStreamObject
   
    ' Use MapPath function to get the Physical Path of file
   
    MyFile = Server.MapPath("textfile.txt")
   
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    Set TSO = FSO.OpenTextFile(MyFile, ForWriting, Create)
   
    TSO.Write "This is first line in this text File" & vbCrLf
    ' Vbcrlf is next line character
    TSO.Write "This is Second line in this text file" & vbCrLf
    TSO.Write "Writen by devasp visitor at " & Now()
    TSO.WriteLine ""
   
    Response.Write " Three lines are writen to textfile.txt <br>"
    Response.Write " Local time at server is " & Now()
   
    ' close TextStreamObject and
    ' destroy local variables to relase memory
    TSO.Close
    Set TSO = Nothing
    Set FSO = Nothing

Regards!
0
TooKoolKrisCommented:
You aren't trying to run these scripts that make use of the stdOut methods by using Wscript.exe are you. In order to properly the StdIn, StdOut, and StdErr streams can be accessed while using CScript.exe only. So you must run these scripts from the command line.

See if this does anything for you but make sure you run it from a prompt using Cscript. When you type something in at the console it's going to tell you what you typed and what line you did it on.

Dim StdIn, StdOut
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut

Do While Not StdIn.AtEndOfStream
     str = StdIn.ReadLine
     StdOut.WriteLine "Line " & (StdIn.Line - 1) & ": " & str
Loop
0
TooKoolKrisCommented:
Here is another one you can play with. The following code starts a batch file and waits for the user input prompt. After entering the needed data through the StdIn stream, the batch file will be able to complete.

Dim WshShell, oExec, input
Set WshShell = CreateObject("WScript.Shell")
Set oExec    = WshShell.Exec("test.bat")
input = ""

Do While True

     If Not oExec.StdOut.AtEndOfStream Then
          input = input & oExec.StdOut.Read(1)
          If InStr(input, "Press any key") <> 0 Then Exit Do
     End If
     WScript.Sleep 100
Loop

oExec.StdIn.Write VbCrLf

Do While oExec.Status <> 1
     WScript.Sleep 100
Loop
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jflannerAuthor Commented:
Folks:

I appreciate the feedback.  I have learned, but I am not there yet.

wsteegmans:  When I try your method, I get an error that leads me to believe "Server" is not instanciated.  (Remember, I am new to VBS, it is probably something very stupid.  But I need complete examples.)

TooKoolKris:  calling my script from the Command Line: "cscript ArithmeticMean.vbs", coupled with your suggested changes works.  But, as the script goes on, I fail at:
requestHTTP.open "POST", myWebService, false

This line works if I call the script directly: "ArithmeticMean.vbs"

I need the complete script to work.  If either of you can help me out, I'll release the points.  Also, anyone know a good vbs book.
0
wsteegmansCommented:
Hi jflanner,

I wrote the script as a real ASP-Script (also VBS, but little different) ...

Here is the real one (without any Server Objects at all):

    ' Set up Constants
    Const ForWriting = 2 ' Input OutPut mode
    Const Create = True
   
    Dim MyFile
    Dim FSO ' FileSystemObject
    Dim TSO ' TextStreamObject
   
    ' Use MapPath function to get the Physical Path of file
   
    MyFile = "c:\temp\textfile.txt"
   
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set TSO = FSO.OpenTextFile(MyFile, ForWriting, Create)
   
    TSO.Write "This is first line in this text File" & vbCrLf
    ' Vbcrlf is next line character
    TSO.Write "This is Second line in this text file" & vbCrLf
    TSO.Write "Just an other line ... written " & Now()
    TSO.WriteLine ""
   
    ' close TextStreamObject and
    ' destroy local variables to relase memory
    TSO.Close
    Set TSO = Nothing
    Set FSO = Nothing

Don't know a good VBS Book. Learned VB and VBA, and VBS is just a simple version of them. So, if you know VB or VBA, you also know a lot of VBS.

Regards!
0
TooKoolKrisCommented:
Well I don't know what to tell you as both scripts work fine for me. Without being in front of your program it's hard to say why they aren't working for you. I assure you nothing is wrong with the scripts however.

The best book for VBS in IMO is this:

Microsoft Windows 2000 Scripting Guide
http://www.amazon.com/exec/obidos/tg/detail/-/0735618674/qid=1070629091/sr=1-1/ref=sr_1_1/102-5718454-3657735?v=glance&s=books
0
briangsCommented:
Your client is running WScript Engine as the default and you are executing a CScript command. Switch to the CScript Engine with the command "wscript /h:cscript" and your command will work fine.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.