1
votes

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
2
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
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
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

2 Answers

1
votes

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 
0
votes

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)