Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: execute vbscript code inline in Perl script

by vinoth.ree (Monsignor)
on Sep 08, 2017 at 03:48 UTC ( #1198899=note: print w/replies, xml ) Need Help??


in reply to execute vbscript code inline in Perl script

There are three ways to run an external program from perl.
The function qx() returns the STDOUT as a string.
The function system returns the vb script exit code.
The function exec never returns.

In your case use qx() to run your vb script and capture the output in a varible like my $final = qx(vbscript)


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^2: execute vbscript code inline in Perl script
by haukex (Bishop) on Sep 08, 2017 at 15:09 UTC
    There are three ways to run an external program from perl.

    There aren't just those three built in to Perl, e.g. there are piped opens, but even so I recommend a module instead.

Re^2: execute vbscript code inline in Perl script
by slick.user (Novice) on Sep 08, 2017 at 16:40 UTC

    I didn't get any value when I execute the command below from Perl.

    my $final = qx("cscript out2.vbs"); print STDOUT "Final: $final\n";

    Final: Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.

    my $final2 = system("cscript out2.vbs"); print STDOUT "Final2: $final2\n";

    Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. Final2: 56320 Is 56320 the process ID from CScript?

    out2.vbs

    Dim num1, num2, final, str num1 = 30 num2 = 50 str = "Final Value: " final = num1*num2 'MSGBOX str & final WScript.Quit(final) 'Wscript.Echo final

      If I echo in vbs, this value didn't store into Perl.

      Dim num1, num2, final, str num1 = 30 num2 = 50 str = "Final Value: " final = num1*num2 'MSGBOX str & final 'WScript.Quit(final) Wscript.Echo final

      my $final = qx("cscript out2.vbs"); print STDOUT "Final: --> $final\n";

      Final: --> Microsoft (R) Windows Script Host Version 5.8

      Copyright (C) Microsoft Corporation. All rights reserved.

      1500

        Try

        #!perl use strict; my $final = qx("cscript out2.vbs //NoLogo"); print "Final: --> $final\n"
        poj

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1198899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-09-19 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?