CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Call a vbscript test.vbs from perl script

 



forumrhb
Novice

Jul 16, 2013, 11:12 PM

Post #1 of 7 (1471 views)
Call a vbscript test.vbs from perl script Can't Post

I am trying to call the vbscript (test.vbs) from perl script test.pl. i am not getting any output or errors for the below programs when i run the perlscript "perl test.pl".

If i run the vbscript from command line "cscript test.vbs" proper output is displayed, if i run the same script in perl it is displaying nothing.

test.pl Perl script:
============================
#use strict;
use warnings;
use win32;
my $cmd = q("cscript test.vbs");
qx($cmd);
============================

test.vbs vb script:
============================
Dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
WScript.Echo sCurPath
WScript.Echo "Simple scripting"
============================[code]


BillKSmith
Veteran

Jul 17, 2013, 4:58 AM

Post #2 of 7 (1465 views)
Re: [raghuhb] Call a vbscript test.vbs from perl script [In reply to] Can't Post

There are three ways to run an external program from perl.

The function qx (or its equivalent back quotes) returns the stdout as a string.

The function system returns the return code.

the function exec never returns.


You are using qx and discarding its return (The output that you expect)

In your case (external program at end of perl script) you should use exec. I doubt that you need the double quotes inside the 'q'.


Code
#use strict;  
use warnings;
use win32;
my $cmd = q("cscript test.vbs");
exec($cmd);

Good Luck,
Bill


FishMonger
Veteran / Moderator

Jul 17, 2013, 6:33 AM

Post #3 of 7 (1461 views)
Re: [raghuhb] Call a vbscript test.vbs from perl script [In reply to] Can't Post

What is your real goal and what results did you expect from this test script?

If executed on its own, test.vbs will produce 2 separate GUI windows displaying the results of the echo statements.

When executing it as a param to cscript, it only outputs the second echo statement to STDOUT (i.e., the cmd window).

When executing $cmd from the perl script (as Bill showed), it also only outputs the second echo statement to STDOUT.

I suspect that result is not exactly what you're wanting.


forumrhb
Novice

Jul 17, 2013, 9:36 PM

Post #4 of 7 (1442 views)
Re: [FishMonger] Call a vbscript test.vbs from perl script [In reply to] Can't Post

I just wanted to know how to run the vb script from perl script.

Bill's code worked for me, i was just trying to call a VB script from perl script.

When i ran the perl script from command line, it displayed both the echo statements on console.

Thanks guys for quick response


forumrhb
Novice

Jul 17, 2013, 10:35 PM

Post #5 of 7 (1436 views)
Re: [raghuhb] Call a vbscript test.vbs from perl script [In reply to] Can't Post

I have another issue in this script, after running the vb script the control is not coming back to perl script.
If i add further statements/commands in perl script these will be not executed. the script stops at the point where vb script is called and vb script will be executed and the statements/commands in perl script written after this line won't be executed .

ex:

#use strict;
use warnings;
use win32;
my $cmd = q("cscript test.vbs");
exec($cmd);
===================> Below statements are not exected
print "Completed \n"
new statement1
new statement2


FishMonger
Veteran / Moderator

Jul 18, 2013, 6:12 AM

Post #6 of 7 (1433 views)
Re: [raghuhb] Call a vbscript test.vbs from perl script [In reply to] Can't Post

See perldoc -f exec

Code
    exec LIST 
exec PROGRAM LIST
The "exec" function executes a system command *and never
returns*; use "system" instead of "exec" if you want it to
return. It fails and returns false only if the command does not
exist *and* it is executed directly instead of via your system's
command shell (see below).

Since it's a common mistake to use "exec" instead of "system",
Perl warns you if "exec" is called in void context and if there
is a following statement that isn't "die", "warn", or "exit" (if
"-w" is set--but you always do that, right?). If you *really*
want to follow an "exec" with some other statement, you can use
one of these styles to avoid the warning:

exec ('foo') or print STDERR "couldn't exec foo: $!";
{ exec ('foo') }; print STDERR "couldn't exec foo: $!";
....
....



Code
use strict; 
use warnings;
use win32;

my $cmd = q(cscript test.vbs);
system($cmd);

# or
print qx($cmd);

print "Completed \n"
#new statement1
#new statement2



(This post was edited by FishMonger on Jul 18, 2013, 6:13 AM)


forumrhb
Novice

Jul 19, 2013, 2:27 AM

Post #7 of 7 (1418 views)
Re: [FishMonger] Call a vbscript test.vbs from perl script [In reply to] Can't Post

Thanks it worked.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives