Hi All,

Apologies straight off for what is essentially a VB question, but answering the question will make dealing VB code from Perl a lot easier for me, and as I have to do theis somewhat often I really would appreciate some consideration on it by you folks.

As we all know controlling external apps from Perl is easy and makes it possible to use Perl as glue. The normal and simplest means of having the processes communicate is over STDIN/STDOUT. What my problem is that it seems to be a real bitch to get VB to write to STDOUT in a useful way. Weve worked the following code out from a MS kb article

Option Explicit Public Const STD_OUTPUT_HANDLE = -11& Public Declare Function stdout Lib "kernel32" Alias "GetStdHandle" _ (Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long Public Declare Function WriteFile Lib "kernel32" _ (ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWri +te As Long, _ lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = +0&) As Long Sub Main() Dim sWriteBuffer As String Dim lBytesWritten As Long Dim hStdOut As Long sWriteBuffer = "This should go to STDOUT" hStdOut = stdout() WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWrit +ten End Sub

And it works. Sortof. If I compile the VB and then run it from the console it appears not to work. However if I pipe it to a file it works fine.

C:\Program Files\Microsoft Visual Studio\VB98>stdout C:\Program Files\Microsoft Visual Studio\VB98>stdout > foo.txt C:\Program Files\Microsoft Visual Studio\VB98>type foo.txt This should go to STDOUT C:\Program Files\Microsoft Visual Studio\VB98>stdout | more This should go to STDOUT C:\Program Files\Microsoft Visual Studio\VB98>stdout | perl -pne '' This should go to STDOUT

So Perl can read it etc, but its somewhat annoying to have to test it like this. Not everybody will realize that it must be piped to something more intelligent. (ha! more.exe considered more intelligent than VB).

If anyone can explain this strange behaviour or tell me what to do to have it behave as expected then Id be much obliged.

BTW, my conscience is clear for asking this question as the above code will almost certainly come in useful for someone wanting to wrap some VB app in a perl script....

Ok, ok, its not that clear. Its VB, and it makes me feel dirty too. :-)


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Getting VB To talk to Perl by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.