Solved

Write to console in VBScript

Posted on 2003-11-29
7
54,784 Views
Last Modified: 2011-08-18
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.  
0
Comment
Question by:jflanner
7 Comments
 
LVL 7

Assisted Solution

by:wsteegmans
wsteegmans earned 250 total points
Comment Utility
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
 
LVL 9

Expert Comment

by:TooKoolKris
Comment Utility
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
 
LVL 9

Accepted Solution

by:
TooKoolKris earned 250 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jflanner
Comment Utility
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
 
LVL 7

Expert Comment

by:wsteegmans
Comment Utility
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
 
LVL 9

Expert Comment

by:TooKoolKris
Comment Utility
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
 

Expert Comment

by:briangs
Comment Utility
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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now