0

I have a classic ASP page that needs to access a file generated via a PHP script. Is it possible to call the PHP script somehow, from within VBScript?

And before anyone asks, I do not have the time to port either script. They are both very complex and I only need a short term solution at this time.

Now the below is not generating errors, but the file is not being generated. I'm ready to give up.

str = "D:\TTnav_Alpha\Alpha\Framework\EnvMgr\generate_jira_list.php"
Set objShell = CreateObject("WScript.Shell")
'response.write(str)
objShell.Run """C:\Program Files (x86)\PHP\php.exe"" " & str ,3,true
Set objShell = Nothing
ZygD
  • 8,011
  • 21
  • 49
  • 67
prufrock
  • 237
  • 1
  • 4
  • 14
  • Not clear: Do you just want to access the file from vbscript, or do you need to process the file first using the PHP program? Do you need to give the PHP program any input arguments? Will it output a response that you need to capture? Does it need to run in a web server environment or can it run from the command line? Do your ASP and PHP environments both have read/write permission to the file? Are they third party programs or in-house code? There's probably quite a few other issues to consider, but that's just my initial thoughts. – Spudley Oct 08 '13 at 14:36
  • The asp script needs to access the file generated by the php script. I want to execute the php script from within the asp script to ensure the file is up to date. clear enough?? – prufrock Oct 08 '13 at 15:42
  • Yep, that's useful additional info. Re your current attempt, you might want to double-up the backslashes in the path to escape them. – Spudley Oct 08 '13 at 15:59

2 Answers2

0

Just invoke WScript.Shell as explained at How do I execute a DOS command / batch file / exe from ASP?

<% 
' Untested
set wshell = CreateObject("WScript.Shell") 
wshell.run "c:\dos\php c:\site\script.php" 
set wshell = nothing 
%>

Edit: You are now trying to execute this:

C:\Program Files (x86)\PHP\php.exeD:\TTnav_Alpha\Alpha\Framework\EnvMgr\generate_jira_list.php

This is an invalid command (if you copy it to a command prompt, it won't run). You need to quote the paths with spaces and separate the command from the argument:

"C:\Program Files (x86)\PHP\php.exe" D:\TTnav_Alpha\Alpha\Framework\EnvMgr\generate_jira_list.php

In VBScript you escape quotes doubling them so you want:

objShell.Run """C:\Program Files (x86)\PHP\php.exe"" " & str,3,false

By the way, that 3 means Activates the window and displays it as a maximized window. Don't forget to remove it before going live.

Ref: Run Method (Windows Script Host)

Community
  • 1
  • 1
Álvaro González
  • 128,942
  • 37
  • 233
  • 325
  • I tried something similar, but does not work. I added it to my question. – prufrock Oct 08 '13 at 15:53
  • I've seen your edit, where you copy my code and just dump "does not work" without further details. Your version does not even look as valid VBScript. Do you need help [escaping quotes](http://stackoverflow.com/questions/2942554/vbscript-adding-quotes-to-a-string)? – Álvaro González Oct 08 '13 at 15:58
  • Maybe. Im not getting any feedback after I run it. I have tried escaping quotes. but still, I do not receive an error. And I know the php script works. I have been running it from the command line, manually. – prufrock Oct 08 '13 at 16:04
  • According to [docs](http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.84%29.aspx>), the `run` method returns *any error code returned by the program*; check that. You can also [redirect stdout and stderr to a file](http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html) so you can look at it. – Álvaro González Oct 08 '13 at 16:10
  • Making progress. I tweaked the code and am now getting an error. looks like file not found. – prufrock Oct 08 '13 at 16:31
0

My .vbs code successfully calls a script in .php file.

In my .vbs file I have this:

set wshell = CreateObject("WScript.Shell")
wshell.Run "C:\xampp\php\php.exe -f C:\Temp\test2.php"
set wshell = nothing

Double quotes must enclose the path if there are spaces within the path, e.g.:

set wshell = CreateObject("WScript.Shell")
wshell.Run """C:\my xampp dir\php\php.exe"" " & "-f C:\Temp\test2.php"
set wshell = nothing 
ZygD
  • 8,011
  • 21
  • 49
  • 67