【问题标题】:Executing php script with parameter using powershell使用powershell执行带参数的php脚本
【发布时间】:2020-10-14 11:50:26
【问题描述】:

我正在尝试调用 PHP 文件,使用 Powershell 在本地 URL 中传递 request_number

在 HTML 中:

<a href='workflow_execution_progress.php?view_id=".$row['request_number']."' title='Click to see the progress of workflow'>

我参考了这个链接,但不确定是否使用参数对其进行修改。 Executing php script on powershell

更新:我的 PowerShell

$PhpExe  = "C:\path\to\php\install\dir\php.exe"
$PhpFile = "C:\path\to\script.php"
$PhpArgs = '-f "{0}"' -f $PhpFile  //args like view_id = 1 / 2 /3 (dynamically)
$PhpOutput = & $PhpExe $PhpArgs

【问题讨论】:

  • 如果通过powershell调用本地PHP文件,则不涉及“url”(因为您没有发出网络请求)。
  • 是的,它现在是本地文件。将在项目完成后部署。我的问题是如何使用 PowerShell 脚本 @MagnusEriksson 将动态 id 传递给 PHP 文件
  • @MagnusEriksson 抱歉,我不知道如何在我的 powershellcode 中添加它 $PhpExe = "C:\path\to\php\install\dir\php.exe" $PhpFile = "C: \path\to\script.php" $PhpArgs = '-f "{0}"' -f $PhpFile

标签: php powershell parameter-passing


【解决方案1】:

您可以使用$argv 获取传递给脚本的参数数组。

https://www.php.net/manual/en/reserved.variables.argv.php

php script.php arg1 arg2 arg3

<?php
var_dump($argv);
?>

array(4) {
  [0]=>
  string(10) "script.php"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}

【讨论】:

  • 抱歉,我不知道如何在我的 powershellcode 中添加它 $PhpExe = "C:\path\to\php\install\dir\php.exe" $PhpFile = "C:\path \to\script.php" $PhpArgs = '-f "{0}"' -f $PhpFile
  • 也许我不明白你的问题。我不确定是关于如何将参数传递给脚本,还是如何传递参数?
  • 需要使用 powershell 脚本将参数传递给 PHP 文件。 - 如何传递参数
  • 我不明白。我阅读了您的更新,但为什么不在 $Phpfile 之后放置参数? $PhpArgs = '-f "{0}"' -f $PhpFile 'view_id=1'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-09
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
  • 2013-07-25
  • 2011-07-16
  • 2010-10-06
相关资源
最近更新 更多