php - 从 powershell 传递到批处理时丢失部分 url

标签 php powershell batch-file

我有一些 powershell 连接到我的服务器并返回要传递到批处理文件的地址。

此批处理文件是必需的,因为它是 HTA/批处理混合文件,允许我运行为项目创建的 UI。 URL 作为 iframe 源传递以从服务器加载一些结果。

我在powershell中有一个变量$content,它等于http://example.com/selectMultiple.php?choice=[{"id":51,"p": 100},{"id":52,"p":94}](稍作修改以保护我的服务器地址)

然后我启动批处理文件,同时将 $content 变量传递给它,如下所示

"Launching $content"
Start-Process "files\hybrid.bat" "$content"

在批处理文件中,我有一些代码回显传递给它的值。

set "link=%~1"
echo %link%

但是在传递之后,一些变量被修剪了。这与 http://example.com/selectMultiple.php?choice 相呼应 - 这让我相信 = 符号中的某些内容正在破坏字符串。

我已经在 powershell 和我的服务器 (php) 中尝试了 urldecode 方法,但都没有解决问题。

我在这里不知所措,非常感谢任何解决此问题的帮助。/

(我也标记了 PHP,以表明我确实有能力使用返回 URL 的代码)

最佳答案

Start-Process "files\hybrid.bat" """$content"""

请注意,$content 变量包含被视为 parameter delimiters 的字符(例如 =,)在批处理脚本中:

Delimiters separate one parameter from the next - they split the command line up into words.

Parameters are most often separated by spaces, but any of the following are also valid delimiters:

  • Comma (,)
  • Semicolon (;)
  • Equals (=)
  • Space ( )
  • Tab ( )

被调用的批处理(参见set "link=%~1"命令)以正确的方式将第一个提供的参数从双引号中去掉。因此,您需要从 $content 变量 enclosed in double quotes from powershell 传递字符串。 。使用双内部双引号,如下所示:

#                                ↓            ↓ string delimiters are not supplied
Start-Process "files\hybrid.bat" """$content"""
#                                 ↑↑        ↑↑  escaped inner double quotes are supplied

Double-Quoted Strings (")

When you enclose a string in double quotation marks, any variable names in the string such as "$myVar" will be replaced with the variable's value when the command is processed. … Any embedded double quotes can be escaped using the grave-accent as `" or doubled (replace " with "").

关于php - 从 powershell 传递到批处理时丢失部分 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44525799/

相关文章:

javascript - JS和PHP中表格添加到数组后仅显示部分列

windows - 在超时命令中跳过按 CTRL+C

php - 如何使用 php 签署 android 应用程序?

php - 如何正确使用 CASE..WHEN 使用 PDO

php - Magento:在 X 号之后向访问者显示弹出窗口。页数

powershell - 文件操作因 New-PSSession 失败

powershell - 使用 powershell 命令在 Azure 中创建 VM 时出现错误

Powershell获取文件的元数据

batch-file - 来自批处理文件的 http Web 请求

batch-file - 批处理 : Shutdown PC if a Program isn't Running?