There is a simple function in VB called "Shell", which can be used to execute 
any external program. I am using it quite often to run a Perl script from 
within VB or VBA.

You simply make a call like doing it from the command line:

Shell "C:\Perl\perl.exe test.pl <your args>"

To remember is however, that the execution is asynchronous, i.e. your VB 
application will not wait until the script is ready; you also cannot receive 
any output from the script in this way.

To overcome this shortage, I let the script write output into a file (e.g. into 
a Temp directory) and VB is waiting in a loop until this file is ready to read 
out of it:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'Practical 
auxiliary function – "Sleep" from kernel32.dll

Dim outFile As String, outputReady as Boolean, i as integer

outfile = Environ("TEMP") & "\" & "perlout.txt"                 'Just an 
example – here with "TEMP" directory read out from environment

Kill outfile                                                    'Remove any old 
outfile, you can check for it's existence first

Shell "C:\Perl\perl.exe test.pl <your args>"                    'Call Perl 
script

      Do                                                              'Wait for 
output

        Sleep 100                                                     'Check 
every 100 msec

        i = i + 1                                                     'Counter

        If Dir(outfile) = "perlout.txt" Then _                        
'Dir(outfile) = "perlout.txt" checks for existence of "perlout.txt".

          outputReady = FileLen(outFile) > 0                          'If 
outfile is created, check if it's already written. If so, then output is

      Loop Until outputReady or i > 100                               'ready, 
but your Perl script should write to outfile just once when finished.

                                                                      'The loop 
itself should also be somehow limited in case the Perl script will
                                                                      'fail.

Now you can read outfile in VB.

 

Regards & greetings,

 -- Andreas

________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, June 25, 2008 12:01 PM
To: activeperl@listserv.activestate.com
Subject: Communication between Perl and VB script

 

Hi All,

 

         I want to call a Perl script ( assume test.pl )  in VB script 
(final.vbs). Is it possible to do this?

If it is, could you please send me a snippet of the code?

 

Thanks for great help. 

 

Regards,

Mustafa

 

Please do not print this email unless it is absolutely necessary. 

The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email. 

www.wipro.com 


****************************************************************************************
Note:  If the reader of this message is not the intended recipient, or an 
employee or agent responsible for delivering this message to the intended 
recipient, you are hereby notified that any dissemination, distribution or 
copying of this communication is strictly prohibited. If you have received this 
communication in error, please notify us immediately by replying to the message 
and deleting it from your computer. Thank you. 
****************************************************************************************
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to