将参数从 PHP 传递到 Powershell exec [英] Passing Params from PHP to Powershell exec

查看:67
本文介绍了将参数从 PHP 传递到 Powershell exec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 PHP 脚本,它允许我选择几个文件从预定位置下载.我希望我的脚本将一个数组传递给一个 id 之前编写的 Powershell 脚本,并让我的 Powershell 脚本 处理下载(基本上 php 文件只需要告诉powershell 文件需要下载什么).我查看了一些选项,似乎 exec 是我应该使用的命令(因为我不关心命令行输出,我不需要 shell_exec).

I am attempting to write a PHP script that will allow for me to select a few files to download from a predetermined location. I'd like my script to pass an array to a Powershell script that id written earlier and have my Powershell script handle the downloading (basically the php file just needs to tell the powershell file what needs to be downloaded). I've looked at a few options, and it seems that exec is the command I should use for this (as I do not care about command line output I shouldnt need shell_exec).

到目前为止,我已经关闭了 OFF 安全模式以允许我使用此命令.我还应该注意到 php 文件将从服务器运行,但是 powershell 文件位于本地机器上.

So far I've turned OFF safe mode to allow me to use this command. I should also note that the php file will be run from a server, however the powershell files are located on a local machine.

到目前为止处理参数传递的代码片段如下所示:

A snippet of the code so far to handle the param passing looks like this:

if(isset($_POST['formSubmit'])) 
{
    $choosePlugin = $_POST['wpPlugin'];
    $chooseTheme = $_POST['wpTheme'];

    if(isset($_POST['wpTheme'])) 
    {
        echo("<p>You selected: $chooseTheme</p>\n");
        exec('powershell.exe C:\Wordpress Setup\setupThemes.ps1 $chooseTheme');

    } 
    else 
    {
        echo("<p>You did not select a theme</p>\n");
    }

我对应该在 exec 中放入什么感到有些困惑.当我运行上面的代码时,没有错误但是没有任何反应.我对此有点陌生,因此如果需要更多信息,我深表歉意.感谢您提供任何帮助.

I am a bit confused as to what I should put inside the exec. When I run the above code there are no errors however nothing happens. I am a bit new to this so I apologize if more information is required. Any help is appreciated thank you.

推荐答案

尝试做:

echo exec('powershell.exe C:\\Wordpress Setup\\setupThemes.ps1 $chooseTheme');

查看powershell.exe的结果(记住双\),还要确保把exe文件的绝对路径:

to see the results of powershell.exe (remember the double \), also make sure to put the absolute path to the exe file:

 echo exec('c:\\PATH_TO_POWERSHELL.EXE\\powershell.exe C:\\Wordpress Setup\\setupThemes.ps1 $chooseTheme');

这篇关于将参数从 PHP 传递到 Powershell exec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆