Solved

Write to console in VBScript

Posted on 2003-11-29
7
56,442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 7

Assisted Solution

by:wsteegmans
wsteegmans earned 250 total points
ID: 9843890
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
ID: 9849938
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
ID: 9849949
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jflanner
ID: 9878867
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
ID: 9880654
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
ID: 9881918
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
ID: 23150167
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 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