从 VBScript 执行 PHP 脚本


Executing a PHP script from VBScript

我有一个经典的ASP页面,需要访问通过PHP脚本生成的文件。是否可以从 VBScript 中以某种方式调用 PHP 脚本?

在任何人问之前,我没有时间移植任何一个脚本。它们都非常复杂,我目前只需要一个短期解决方案。

现在,以下内容未生成错误,但未生成文件。我准备放弃。

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

我的 .vbs 代码成功调用了.php文件中的脚本。

在我的.vbs文件中,我有这个:

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

如果路径中有空格,则必须用双引号将路径括起来,例如:

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

只需调用WScript.Shell,如如何从ASP执行DOS命令/批处理文件/exe中所述?

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

编辑:您现在正在尝试执行以下命令:

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

这是一个无效的命令(如果将其复制到命令提示符,它将不会运行)。您需要用空格引出路径并将命令与参数分开:

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

在 VBScript 中,您可以转义引号将它们加倍,因此您需要:

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

顺便说一下,3这意味着激活窗口并将其显示为最大化窗口。在上线之前不要忘记将其删除。

参考: 运行方法 (Windows 脚本主机)