![Powershell:使用字符串作为多个参数](https://linux22.com/image/1687062/Powershell%EF%BC%9A%E4%BD%BF%E7%94%A8%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BD%9C%E4%B8%BA%E5%A4%9A%E4%B8%AA%E5%8F%82%E6%95%B0.png)
我在 PowerShell 中有一个字符串变量,$t="foo bar"
它应该作为参数传递给命令“start-process”。
我的“启动过程”需要多个参数,即“foo”和“bar”,而不是“foo bar”,这不起作用:
start-process $t
怎样将其分割$t
开来start-process foo bar
?
我无法手动拆分它,因为“启动进程”接收任意数量的参数。
答案1
以下代码将解决您的问题:
$split1,$split2 = $t.split()
Start-Process $split1 -ArgumentList $split2
假设字符串中没有特殊字符,或者strSeparator
使用
分割功能。