Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set the return value from cscript.exe

1,680 views
Skip to first unread message

Richard Muller

unread,
May 15, 2003, 5:06:56 PM5/15/03
to
Hi All,

I invoke cscript.exe (along with an argument which is the name of a vbs
script) from within a Ruby script (Ruby is sort of an object-orient Perl,
plus more). I capture the return value from cscript.exe and print it.
What I get is a two-line output:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Is there any way for me to return a string of my choice programmatically
with a .vbs command? I don't see any "return" statement documented for .vbs

Thanks in advance.
--
Regards,
Richard

Question: How does a lawyer sleep at night? He lies on one side, then turns
over and lies on the other!


Torgeir Bakken (MVP)

unread,
May 15, 2003, 5:57:16 PM5/15/03
to
Richard Muller wrote:

> Hi All,
>
> I invoke cscript.exe (along with an argument which is the name of a vbs
> script) from within a Ruby script (Ruby is sort of an object-orient Perl,
> plus more). I capture the return value from cscript.exe and print it.
> What I get is a two-line output:
>
> Microsoft (R) Windows Script Host Version 5.6
> Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
>
> Is there any way for me to return a string of my choice programmatically
> with a .vbs command? I don't see any "return" statement documented for .vbs

Hi

Try this:

Create a .vbs file with the name TestStringReturn.vbs with this content:

Wscript.Echo "This is my returning text to StdOut"

Run it with the following command in a command prompt:


CScript.exe //Nologo TestStringReturn.vbs

If you want to return a numeric errorlevel from a vbscript, you can also do that
(7 in this example):

WScript.Quit 7


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Richard Muller

unread,
May 16, 2003, 4:04:02 AM5/16/03
to
Thank you VERY much for your response (with the added info about numeric
return values, too!)

FYI, here's the code I wrote in Ruby and ran under the SciTE IDE:

require "Win32API"
retval =`cscript.exe Test_StringReturnVal.vbs`
puts "Return value = " + retval

That produced the same result in SciTE's output pane that I received when I
ran the cscript command in a Command window.

Neat stuff.

Regards,
Richard

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3EC40D3C...@hydro.com...

Richard Muller

unread,
May 16, 2003, 4:09:39 AM5/16/03
to
Woops. I just noticed that the returned string from cscript had three lines
preceding the value supplied to the WScript.Echo command. Of course, that's
no problem. I can strip them in the Ruby script, so the result is still
perfect for my purposes.


Torgeir Bakken (MVP)

unread,
May 16, 2003, 6:30:32 AM5/16/03
to
Richard Muller wrote:

Hi

To avoid those preceding lines, you can use CScript.exe //Nologo

0 new messages