我使用Octopush仪表板:
屏幕截图代码为我提供了TFS更改集列表。 所以我已经有了我的ID列表。 我需要运行一些exe文件并将参数传递给此exe 通过C#进行以下方式:
string cParams = "\"Test proj name\" " + "3.22.652.965863 " + "QA " + "false " + "463841" + " 464268" + " 463450" + " 463841" + " 463167" + " 458908" + " 462917" + " 462780" + " 462429" + " 461225" + " 460414";
var proc = System.Diagnostics.Process.Start(@"\\ptnas1\home_dirs\michaelb\Documents\Visual Studio 2015\Projects\Changesetes\Changesetes\bin\Debug\Changesetes.exe", cParams);
或者在PowerShell中它以这种方式工作:
start "" "\\ptnas1\home_dirs\michaelb\Documents\Visual Studio 2015\Projects\Changesetes\Changesetes\bin\Debug\Changesetes.exe" "Test proj name" 3.22.652.965863 QA false 463841 464268 463450 463841 463167 458908 462917
pause
我需要将我的硬编码的“proj name”,“version num”,“string1”,“false”以及我收到的ID列表组合在一起。 如何在Powershell中使其工作?
答案 0 :(得分:1)
$Exe = '\\ptnas1\home_dirs\michaelb\Documents\Visual Studio 2015\Projects\Changesetes\Changesetes\bin\Debug\Changesetes.exe'
$Params = "Test proj name " + "3.22.652.965863 " + "QA " + "false " + "463841" + " 464268" + " 463450" + " 463841" + " 463167" + " 458908" + " 462917" + " 462780" + " 462429" + " 461225" + " 460414"
&$Exe $Params
依赖于您的本机命令,您可能需要先将params作为数组加入
$Params = "Test proj name","3.22.652.965863","QA ","false" [etc.]
&$Exe $Params
使用您的示例,您仍然可以继续使用System.Diagnostics.Process:
[System.Diagnostics.Process]::Start($Exe,$Params)
另一种选择是使用WMI:
([WMICLASS]"ROOT\CIMV2:Win32_Process").Create("$Exe $Params")
当然,PowerShell Start-Process
带有-ArgumentList
参数
修改强>
分离常量和动态变量,
$Exe = `\\ptnas1\home_dirs\michaelb\Documents\Visual Studio 2015\Projects\Changesetes\Changesetes\bin\Debug\Changesetes.exe`
$Constants = "Test proj name","3.22.652.965863","QA" etc.
$Dynamic = "462917","462780","462429","461225","460414"
&$Exe $Constants $Dynamic
或使用其他执行选项之一
答案 1 :(得分:0)
$argumentList = "`"Test proj name`" 3.22.652.965863 QA false 463841 464268 463450 463841 463167 458908 462917"
start-process -FilePath "\\ptnas1\home_dirs\michaelb\Documents\Visual Studio 2015\Projects\Changesetes\Changesetes\bin\Debug\Changesetes.exe" -ArgumentList $argumentList
答案 2 :(得分:0)
我的回答基于Avshalom建议修改后的代码:
$Exe = `\\ptnas1\home_dirs\michaelb\Documents\Visual Studio
2015\Projects\Changesetes\Changesetes\bin\Debug\Changesetes.exe`
$Constants = "Test proj name","3.22.652.965863","Dev","false"
$Dynamic = "462917","462780","462429","461225","460414"
$all = $Constants + $Dynamic | select -uniq
&$Exe $all
问题是不可能以这种方式将两个参数传递给.NET concole应用程序:
$Exe = `\\ptnas1\home_dirs\michaelb\Documents\Visual Studio 2015\Projects\Changesetes\Changesetes\bin\Debug\Changesetes.exe`
$Constants = "Test proj name","3.22.652.965863","QA" etc.
$Dynamic = "462917","462780","462429","461225","460414"
&$Exe $Constants $Dynamic
因为应用程序永远不会收到最后一个参数。我认为powershell只是忽略了第二个。