powershell - 将变量传递给启动 powershell 命令
问题描述
我想将字符串变量传递给在新的 powershell 窗口中运行的命令。
$word = "bird"
start PowerShell { echo $word; pause }
我该怎么做呢?
解决方案
不知何故,它在没有大括号的情况下效果更好,并使用双引号来解释变量。我猜脚本块被启动进程转换为字符串。“Powershell -Command”是隐含的。
start powershell "echo $word; pause"
或者这适用于呼叫操作员:
start PowerShell "& { echo $word; pause }"
“电源外壳 -?” 有点涉及到这一点。
-Command
...
If the value of Command is a script block, the script block must be enclosed
in braces ({}). You can specify a script block only when running PowerShell.exe
in Windows PowerShell.
...
If the value of Command is a string, Command must be the last parameter
in the command , because any characters typed after the command are
interpreted as the command arguments.
To write a string that runs a Windows PowerShell command, use the format:
"& {<command>}"
where the quotation marks indicate a string and the invoke operator (&)
causes the command to be executed.
推荐阅读
- data-science - 对于两个 AUC(曲线下面积) - 我如何对非劣效性进行功效分析?
- firebase - 另一个地图中地图中 Firestore 的安全规则
- java - 正则表达式在在线测试器中捕获了我想要的所有内容,但在 Java 中捕获了额外的字符
- javascript - 在 React 或 Javascript 中,我们如何为 Google Cloud Firestore 提供自定义文档 ID
- python - 代码签名 GUI python 应用程序以在 macos 上进行公证
- bazel - Bazel 构建不正确。os.bzl 出错
- foreach - 可变参数的解构迭代,如 D 中的元组序列
- c - SYSCALL() 在 Linux 中的实现在哪里?
- upwork-api - 将工作申请列为自由职业者,输出字段“状态:工作申请的当前状态”整数映射到什么?
- c# - .NET Core 5 中的 MaxModelValidationErrors = 1