Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Getting VB To talk to Perl

by demerphq (Chancellor)
on Jul 23, 2003 at 11:15 UTC ( [id://277101]=perlquestion: print w/replies, xml ) Need Help??

demerphq has asked for the wisdom of the Perl Monks concerning the following question:

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...

Replies are listed 'Best First'.
Re: Getting VB To talk to Perl
by castaway (Parson) on Jul 23, 2003 at 13:04 UTC
    VB can't build console apps per default, you'll need to 'cheat' and force it to. Eg with http://www.vbadvance.coms little app (free for making console apps, so they claim).

    C.

      castaway, theorbtwo better watch out. I love you babe! This works perfectly. And I just filled out a PO.

      ++castaway


      ---
      demerphq

      <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
Re: Getting VB To talk to Perl
by BrowserUk (Patriarch) on Jul 23, 2003 at 13:41 UTC

    Looks like you already have an answer to this but you may find that using the exetype utitlity that comes with AS perl distributions would get you what you want? As in

    exetype VBapp.exe CONSOLE

    I don't have VB, so I can't test this speculation.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

      Yes this works too. Thanks!


      ---
      demerphq

      <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
Re: Getting VB To talk to Perl
by JaWi (Hermit) on Jul 23, 2003 at 12:43 UTC
    This seems like you forgot to flush the output handle in your VB script.
    IIRC the output to a console is not automatically flushed when an application exits.

    HTH,

    -- JaWi

    "A chicken is an egg's way of producing more eggs."

      I checked that, it wasn't it. But thanks. :-)


      ---
      demerphq

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://277101]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found