To pick up on what NetWallah wrote, personally I usually recommend using a module instead of Perl's builtins like qx// because modules will give you more features and better error handling. In this case, I might suggest IPC::System::Simple's systemx and capturex (the only downside in this case is that STDERR can't be captured, but it doesn't look to me like you need that, although I could be wrong). If you are worried about where the script files might be written, or that they might get overwritten, you could use temporary files (which will have unique names) via the core module File::Temp, like this:

use warnings; use strict; use File::Temp qw/tempfile/; use IPC::System::Simple qw/capturex/; my ($tfh,$tfn) = tempfile( SUFFIX=>'.vbs', UNLINK=>1 ); print $tfh <<'END_VBS'; Dim num1, num2, final num1 = 30 num2 = 50 final = num1*num2 WScript.Echo(final) END_VBS close $tfh; print "running $tfn\n"; # Debug my $final = capturex('cscript','//nologo',$tfn); chomp($final); print "final: '$final'\n";

(not fully tested because I'm not on Windows at the moment)

To have the scripts created in a specific directory, you can use tempfile( ..., DIR=>"C:\\Some\\Path" ). The UNLINK option causes the temporary file to be deleted when the script ends.


In reply to Re^3: execute vbscript code inline in Perl script by haukex
in thread execute vbscript code inline in Perl script by slick.user

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.