[英]passing variable into start powershell command
我想将字符串变量传递给在新的 powershell 窗口中运行命令。
$word = "bird"
start PowerShell { echo $word; pause }
我该怎么做呢?
不知何故,它在没有大括号的情况下效果更好,并使用双引号来解释变量。 我猜脚本块会被 start-process 转换为字符串。 “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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.