如何在powershell中混合参数字符串
How to mix parameter strings in powershell
我需要将一些参数传递给 powershell 中的这个启动进程命令。到目前为止一直无法将参数传递给应用程序。好像我不能用引号将我的参数括在应用程序中,没有它们,命令工作正常。
Start-Process "c:\app\myApp.exe /S '/V /qn AllUsers=1 SN=123-456' " -NoNewWindow -Wait -PassThru
有什么方法可以在 powershell 中合并引号内的引号吗? ...谢谢
你可以试试这个方法
Start-Process -FilePath "c:\app\myApp.exe" -ArgumentList "/S","'/V /qn AllUsers=1 SN=123-456'" -NoNewWindow -Wait -PassThru
使用-ArgumentList "arg1","arg2",...
例如:
Start-Process -FilePath "python" -ArgumentList "-c","print('hello')" -NoNewWindow -Wait -PassThru
输出:
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
38 3 508 1476 0.02 4932 4 python
hello
您可以将整个参数列表作为单个字符串提供:
Start-Process -FilePath "c:\app\myApp.exe -ArgumentList "/S '/V /qn AllUsers=1 SN=123-456'" -NoNewWindow -Wait -PassThru
或者
你可以拆分它们
Start-Process -FilePath "c:\app\myApp.exe -ArgumentList "/S","'/V /qn AllUsers=1 SN=123-456'" -NoNewWindow -Wait -PassThru
看起来管道参数是要走的路:-PassThru | Wait-Process; 这让我们解决了问题。 ... 等等。
我需要将一些参数传递给 powershell 中的这个启动进程命令。到目前为止一直无法将参数传递给应用程序。好像我不能用引号将我的参数括在应用程序中,没有它们,命令工作正常。
Start-Process "c:\app\myApp.exe /S '/V /qn AllUsers=1 SN=123-456' " -NoNewWindow -Wait -PassThru
有什么方法可以在 powershell 中合并引号内的引号吗? ...谢谢
你可以试试这个方法
Start-Process -FilePath "c:\app\myApp.exe" -ArgumentList "/S","'/V /qn AllUsers=1 SN=123-456'" -NoNewWindow -Wait -PassThru
使用-ArgumentList "arg1","arg2",...
例如:
Start-Process -FilePath "python" -ArgumentList "-c","print('hello')" -NoNewWindow -Wait -PassThru
输出:
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
38 3 508 1476 0.02 4932 4 python
hello
您可以将整个参数列表作为单个字符串提供:
Start-Process -FilePath "c:\app\myApp.exe -ArgumentList "/S '/V /qn AllUsers=1 SN=123-456'" -NoNewWindow -Wait -PassThru
或者 你可以拆分它们
Start-Process -FilePath "c:\app\myApp.exe -ArgumentList "/S","'/V /qn AllUsers=1 SN=123-456'" -NoNewWindow -Wait -PassThru
看起来管道参数是要走的路:-PassThru | Wait-Process; 这让我们解决了问题。 ... 等等。