[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PHP and VBS

Posted on 2011-03-01
5
Medium Priority
?
816 Views
Last Modified: 2012-05-11
Hi Experts,
We can use PHP exec command to call VBS code.
<?
$arg = 'anything';
exec ("csript script1.vbs $arg" );
?>

1.) How can I get return values of script1.vbs to PHP.
2.) From PHP can I call fn1 function which is inside script1.vbs

BR Dushan.
0
Comment
Question by:Dushan De Silva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 35012578
Hi,

1)
I'm not that great with PHP, but I do know that VBScript is only capable of returning an integer value, through the use of
WScript.Quit(#)

However, it looks like you could obtain the output from the command by adding a parameter to the exec method:
http://php.net/manual/en/function.exec.php

So if your VBS had WScript.Echo statements in it, then the PHP array should hold that output.

2)
No, you cannot "include" any code in the page for global execution other than php.  If you want to use it, you'd need to convert it.

Regards,

Rob.
0
 
LVL 17

Author Comment

by:Dushan De Silva
ID: 35012673
Hi Rob,
Thanks a lot again!
1.) Fantastic!, I will use WScript.Echo and will capture it from PHP as array.
2.) Can I call VBS function from command line. (then I can try to execute that command using php exec or shell_exec)

BR Dushan.
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 2000 total points
ID: 35012908
1) Sure, hopefully it works.
2) I guess you could.  If you're VBS had something like this:

 
strFunction = WScript.Arguments.Item(0)

Execute "Call " & strFunction

Function MyFunction1
	WScript.Echo "Function1 was called."
End Function

Function MyFunction2
	WScript.Echo "Function2 was called."
End Function

Open in new window


and then you used this PHP:
$arg = 'Function1';
exec ("csript script1.vbs $arg",$arroutput,$returnvalue);

Then it should work (I think).

Regards,

Rob.
0
 
LVL 17

Author Closing Comment

by:Dushan De Silva
ID: 35013077
Yes, thanks lot!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35013102
No worries.

Thanks for the grade,

Regards,

Rob.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question