So I have a powershell script that is supposed to run an executable with an argument to pass to set which method I want to run, and I need to pass a parameter, which is a directory to a config file. So this is what I have
所以我有一个powershell脚本应该运行一个带有参数的可执行文件来传递以设置我想要运行的方法,并且我需要传递一个参数,这是一个配置文件的目录。所以这就是我所拥有的
Start-Process -FilePath "C:\Program Files\MSBuild\test.exe" -ArgumentList /genmsi/f $MySourceDirectory\src\Deployment\Installations.xml
/f is the shortname and file is the long name for my attribute... I get an error in powershell telling me that a positional parameter cannot be found for /f or /file.
/ f是短名称,文件是我的属性的长名称...我在powershell中收到错误,告诉我无法找到/ f或/ file的位置参数。
Any thoughts?
有什么想法吗?
4 个解决方案
#1
45
Try quoting the argument list:
尝试引用参数列表:
Start-Process -FilePath "C:\Program Files\MSBuild\test.exe" -ArgumentList "/genmsi/f $MySourceDirectory\src\Deployment\Installations.xml"
You can also provide the argument list as an array (comma separated args) but using a string is usually easier.
您还可以将参数列表作为数组(逗号分隔的args)提供,但使用字符串通常更容易。
#2
24
Here is an alternative method for doing multiple args. I use it when the arguments are too long for a one liner.
这是执行多个args的另一种方法。当参数对于一个班轮来说太长时,我会使用它。
$app = 'C:\Program Files\MSBuild\test.exe'
$arg1 = '/genmsi'
$arg2 = '/f'
$arg3 = '$MySourceDirectory\src\Deployment\Installations.xml'
& $app $arg1 $arg2 $arg3
#3
22
I was able to get this to work by using the Invoke-Expression
cmdlet.
我能够通过使用Invoke-Expression cmdlet使其工作。
Invoke-Expression "& `"$scriptPath`" test -r $number -b $testNumber -f $FileVersion -a $ApplicationID"
#4
4
Just adding an example that worked fine for me:
只需添加一个适合我的示例:
$sqldb = [string]($sqldir) + '\bin\MySQLInstanceConfig.exe'
$myarg = '-i ConnectionUsage=DSS Port=3311 ServiceName=MySQL RootPassword= ' + $rootpw
Start-Process $sqldb -ArgumentList $myarg
#1
45
Try quoting the argument list:
尝试引用参数列表:
Start-Process -FilePath "C:\Program Files\MSBuild\test.exe" -ArgumentList "/genmsi/f $MySourceDirectory\src\Deployment\Installations.xml"
You can also provide the argument list as an array (comma separated args) but using a string is usually easier.
您还可以将参数列表作为数组(逗号分隔的args)提供,但使用字符串通常更容易。
#2
24
Here is an alternative method for doing multiple args. I use it when the arguments are too long for a one liner.
这是执行多个args的另一种方法。当参数对于一个班轮来说太长时,我会使用它。
$app = 'C:\Program Files\MSBuild\test.exe'
$arg1 = '/genmsi'
$arg2 = '/f'
$arg3 = '$MySourceDirectory\src\Deployment\Installations.xml'
& $app $arg1 $arg2 $arg3
#3
22
I was able to get this to work by using the Invoke-Expression
cmdlet.
我能够通过使用Invoke-Expression cmdlet使其工作。
Invoke-Expression "& `"$scriptPath`" test -r $number -b $testNumber -f $FileVersion -a $ApplicationID"
#4
4
Just adding an example that worked fine for me:
只需添加一个适合我的示例:
$sqldb = [string]($sqldir) + '\bin\MySQLInstanceConfig.exe'
$myarg = '-i ConnectionUsage=DSS Port=3311 ServiceName=MySQL RootPassword= ' + $rootpw
Start-Process $sqldb -ArgumentList $myarg