0

I work with Octopush dashboard:

enter image description here

Code on screenshot brings me a list of TFS change sets. So I already have the list of my IDs. I need to run some exe file and pass parameters to this exe in following way through 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);

Or in PowerShell it works this way:

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

I need to combine betwwen my hard-coded argements "proj name", "version num", "string1", "false" and the list of IDs I received. How can I make it work in Powershell?

3
  • What are you having an issue with? Powershell execution policy's? Calling .exe's? Passing parameters? Or the specific application? You say it works this way and then ask how to make it work, so I'm confused as to what the question is. Commented Sep 12, 2016 at 12:38
  • Have a look at Invoke-Expression in powershell, you could build your code and then run it with the invoke-expression command. Commented Sep 12, 2016 at 12:38
  • Sorry, I wasn't crear. I've edited my question. I need to combine between dynamic array and few constants and pass it as arguemnts to my exe. List of Ids should always be at the end of arguments list. Commented Sep 12, 2016 at 12:47

3 Answers 3

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

Depend on your native command, you might need to join the params as array first

$Params = "Test proj name","3.22.652.965863","QA ","false" [etc.]
&$Exe $Params

Using your Example, you can still keep using System.Diagnostics.Process:

[System.Diagnostics.Process]::Start($Exe,$Params)

Another Option is using WMI:

([WMICLASS]"ROOT\CIMV2:Win32_Process").Create("$Exe $Params")

And of course PowerShell Start-Process with the -ArgumentList Parameter

EDIT

Separate your Constants and Dynamic Variables,

$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

Or use one of the other Execution options

Sign up to request clarification or add additional context in comments.

6 Comments

The last answer looks like it should work. Thank you. I'm going to try it.
It doesn't work. I have the same exception for $Exe, $Constants and $Dynamic: is not recognized as an internal or external command.
what is the exeption?
Exceptions: $Exe it is not recognized as an internal or external command. $Constants it is not recognized as an internal or external command. $Dynamic it is not recognized as an internal or external command.
do test-path $exe is it true?
|
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

1 Comment

How can I concatenate my dinamic array of ids $changesets wtih variables $projName, $version, $envName and $resolve? Something like: $params=$projName+ $version+ $envName + $resolve + $changesets?
0

My answer based on code that suggested by Avshalom that has been modified:

$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

The problem is that it is impossible to pass two parameters to .NET concole application in this way:

$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

Because application never receives that last argument. I suppose powershell just ignore the second one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.