There was a discussion sparked by this back when that
Scripting Clinic article first appeared... Your VB program needs to
execute as a console application. The perception was that there was an
"undocumented VB compile switch" that let you create VB based console
applications, but apparently that wasn't true (at least on one ever disclosed
what the magic switch was ;-)...
There is a way to attach a console window to a VB application
as documented by this KB article:
The KB example code uses kernel32 API calls to allocate a
console, get a handle to stdout, and to write to the console. You *may* be
able to allocate the console as illustrated in the example and then use the
FSO.GetStandardStream in place of GetStdHandle() to get an FSO TextStream
object.
I qualified this with *may* because no one's ever posted
that they have done this successfully.
--
Michael Harris
MVP - Windows Script
Hi
Jef,
Have a look at:
http://msdn.microsoft.com/workshop/languages/clinic/scripting061499.aspExtract
from the article:
"Visual Basic user bonus:
The
stdin/stdout/stderr support is actually implemented in the
FileSystemObject,
so you can now access stdin/stdout/stderr from any Visual
Basic program. As a
Visual Basic programmer, I've been waiting for ages for
this functionality.
"
Jeff Mastry <
jma...@sc.rr.com> wrote in message
news:Uu6u4.26364$gW5.1...@typhoon.southeast.rr.com...
>
Interesting - I've never seen GetStandardStream documented
anywhere
before.
> Thanks.
>
> Anyway, you're getting this
error because your program doesn't have a
> console - and therefore no
StdIn, StdOut or StdErr. You can duplicate this
> problem with VBScript by
running this script with and without cscript.exe:
>
> ===
>
Const StdIn = 0
> Const StdOut = 1
> Const StdErr =
2
>
> Dim fso, out
> Set fso =
CreateObject("Scripting.FileSystemObject")
> Set out =
fso.GetStandardStream( StdOut )
> out.Write "Test"
>
===
>
> without cscript.exe you will get the exact same error: The
handle is
> invalid, but with cscript.exe it works as expected. I may be
wrong, but my
> guess is you need to allocate a console before you can do
this in VB. I
> searched MSDN but didn't find an article that mentions
this technique for
> VB. Could you post the address?
>
>
Jeff
>
> "peter cabus" <
peter...@pandora.be> wrote in
message
>
news:Odpk5mPg$GA.237@cppssbbsa04...