Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - what object can I use to output to console

Reply
 
Old 03-31-2009   #1 (permalink)
Big D


 
 

what object can I use to output to console

I use Wscript.Echo in many of my scripts and it works fine when the
environment default is cscript. Is there is a command I can use for writing
messages to the console and not caring if the scripting engine is wscript or
cscript?(stdout) I don't want to worry about putting cscript in front of all
my scripts to specify.



My System SpecsSystem Spec
Old 03-31-2009   #2 (permalink)
T Lavedas


 
 

Re: what object can I use to output to console

On Mar 31, 10:16*am, "Big D" <BigDa...@xxxxxx> wrote:
Quote:

> I use Wscript.Echo in many of my scripts and it works fine when the
> environment default is cscript. Is there is a command I can use for writing
> messages to the console and not caring if the scripting engine is wscriptor
> cscript?(stdout) I don't want to worry about putting cscript in front of all
> my scripts to specify.
Short answer - NO. The script must be running in the console to
output to it. The default script host can be changed using the //H
command line switch (type cscript /? at a command prompt for more
info).

I don't like this approach, because I prefer most of my scripts to use
the Wscript.exe host. Instead, I installed an association to another
extension that marks a console only script. This is associated with
cscript.exe as the host. For example, I just use a VBC extension to
indicate a script is a console application.

To do this from the command prompt ...

C:\> assoc .vbc=VBCFile
..vbc=VBCFile

C:\>ftype vbcfile=%SystemRoot%\System32\CScript.exe "%1" %*

Then add that extension to the PATHEXT variable in the System/Advanced/
Environment Variables dialog.

Then whenever a script that ends with a .VBC extension is invoked
(even from a GUI window) it will use the cscript.exe host. If
invoked by double-click in a GUI window, the script will run in a
console window - but it will disappear immediately after it finishes
(unless the script has a WSH.STDIN.READALL statement to create a pause
until Enter condition - or a WSH.SLEEP 5000). That's up to you. But,
basically, the script becomes a console only script.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
My System SpecsSystem Spec
Old 03-31-2009   #3 (permalink)
Pegasus [MVP]


 
 

Re: what object can I use to output to console


"Big D" <BigDaddy@xxxxxx> wrote in message
news:e3IWItgsJHA.4968@xxxxxx
Quote:

>I use Wscript.Echo in many of my scripts and it works fine when the
>environment default is cscript. Is there is a command I can use for writing
>messages to the console and not caring if the scripting engine is wscript
>or cscript?(stdout) I don't want to worry about putting cscript in front of
>all my scripts to specify.
The function wscript.echo is not available under wscript.exe and it
automatically defaults to msgbox. You could can get around the issue by
forcing cscript.exe to be the default interpreter. Type cscript /? to see
how it's done.


My System SpecsSystem Spec
Old 03-31-2009   #4 (permalink)
ekkehard.horner


 
 

Re: what object can I use to output to console

Big D schrieb:
Quote:

> I use Wscript.Echo in many of my scripts and it works fine when the
> environment default is cscript. Is there is a command I can use for writing
> messages to the console and not caring if the scripting engine is wscript or
> cscript?(stdout) I don't want to worry about putting cscript in front of all
> my scripts to specify.
>
>
As there is no console for a script started with wscript.exe, there is no
easy way to display the output of a wscript-hosted program (other than
in many MsgBoxes). Setting the default script host to cscript.exe (cf.
cscript /?) and/or putting 'catch wscript' code at the start of each script -

Pseudo code:
If scripthost is wscript
start process: cscript.exe script.vbs with all arguments!
exit
End If
... script ...

- are ways to make sure, that your scripts are executed by cscript.exe.

If you want to write the output of a script started with wscript.exe into
a log file, you have to replace all your WScript.Echo calls by calls to
a method of an intelligent logger object that uses the console when executed
under cscript.exe resp. a log file otherwise. One problem of this approach
is that you can't write a method equivalent to WScript.Echo x, ..., z; coming
up with a scheme for the name and setting the mode (append/rewrite) of the
file won't be easy either.
My System SpecsSystem Spec
Old 04-01-2009   #5 (permalink)
Al Dunbar


 
 

Re: what object can I use to output to console


"Todd Vargo" <tlvargo@xxxxxx> wrote in message
news:ORfM8xnsJHA.1088@xxxxxx
Quote:

> Big D wrote:
Quote:

>> I use Wscript.Echo in many of my scripts and it works fine when the
>> environment default is cscript. Is there is a command I can use for
> writing
Quote:

>> messages to the console and not caring if the scripting engine is wscript
> or
Quote:

>> cscript?(stdout) I don't want to worry about putting cscript in front of
> all
Quote:

>> my scripts to specify.
>
> I use this code to force using cscript.exe host in case of accidental
> clicking in Explorer.
>
> Set WshShell = CreateObject("WScript.Shell")
>
> If InStr(Ucase(WScript.FullName), "WSCRIPT.EXE") Then
> 'Restart using CSCRIPT.EXE
> WshShell.Run "CSCRIPT.EXE //nologo " & _
> Chr(34) & Wscript.ScriptFullName & Chr(34)
> Wscript.Quit
> End If
>
> 'These lines are for demo only
> Wscript.Echo "Host is " & WScript.FullName
> WshShell.Popup "Script will close in 5 seconds.",5,"Done"
Some helpful comments all around, one of which might seem appropriate to the
OP.

But if he wants try "console" output, to see what is going on when it is
going on, rather than reading a log file after the fact, or re-launching a
wscript launched script with cscript, another option would be to open an IE
or Word window, and write to it.

/Al


My System SpecsSystem Spec
Old 04-01-2009   #6 (permalink)
Todd Vargo


 
 

Re: what object can I use to output to console

Big D wrote:
Quote:

> I use Wscript.Echo in many of my scripts and it works fine when the
> environment default is cscript. Is there is a command I can use for
writing
Quote:

> messages to the console and not caring if the scripting engine is wscript
or
Quote:

> cscript?(stdout) I don't want to worry about putting cscript in front of
all
Quote:

> my scripts to specify.
I use this code to force using cscript.exe host in case of accidental
clicking in Explorer.

Set WshShell = CreateObject("WScript.Shell")

If InStr(Ucase(WScript.FullName), "WSCRIPT.EXE") Then
'Restart using CSCRIPT.EXE
WshShell.Run "CSCRIPT.EXE //nologo " & _
Chr(34) & Wscript.ScriptFullName & Chr(34)
Wscript.Quit
End If

'These lines are for demo only
Wscript.Echo "Host is " & WScript.FullName
WshShell.Popup "Script will close in 5 seconds.",5,"Done"

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Old 04-01-2009   #7 (permalink)
Alex K. Angelopoulos


 
 

Re: what object can I use to output to console

There is one other technique which is time-honored in multiple scripting
environments for ensuring that specific scripts run as console scripts. It
also resolves the problem of broken console input pipelines on Win32. It
does require an extra script file, but it's straightforward to do.

Assume you want to ensure that the script MyScript.vbs always runs from a
console, and MyScript.vbs is located in c:\apps\bin. What you do is create a
new file named MyScript.cmd and give it the following single-line content:

@cscript %~dpn0.vbs %*

Then you can just run the command "MyScript" if the folder c:\apps\bin is in
your search path or if c:\apps\bin is your current working directory. You
can also specify the path to the batch script instead, even just using
C:\apps\bin\MyScript. Here's what happens.

The command processor automatically matches .cmd files before other script
extensions since .cmd precedes .vbs, etc. in the %pathext% shell variable.
It then runs MyScript.cmd. The initial @ suppresses console output, and the
%~dpn0 gets expanded to the full path of MyScript.cmd, minus the final
extension. The %* becomes any commandline arguments you passed in. So it
looks like this:

@cscript c:\apps\bin\MyScript.vbs <your arguments>

You can use the same content for every wrapper script; just save a .cmd file
with that content in the same folder as your VBScript, with the same base
name as the VBScript. If you're writing a wsf, you would change the content
to read

@cscript %~dpn0.wsf %*

"Big D" <BigDaddy@xxxxxx> wrote in message
news:e3IWItgsJHA.4968@xxxxxx
Quote:

> I use Wscript.Echo in many of my scripts and it works fine when the
> environment default is cscript. Is there is a command I can use for
> writing messages to the console and not caring if the scripting engine is
> wscript or cscript?(stdout) I don't want to worry about putting cscript in
> front of all my scripts to specify.
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
problem grabbing console output PowerShell
output of long lines gets split in PS console PowerShell
Hide console and capture output from script? PowerShell
function return values, console output PowerShell
Need to change console text color of Debug output PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46