将参数从 PHP 传递到 Powershell exec

编程入门 行业动态 更新时间:2024-10-28 00:21:23
本文介绍了将参数从 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

本文发布于:2023-07-07 04:43:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058913.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   PHP   exec   Powershell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!