Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

CMD Line command in POSH

$
0
0

 

I have a 3rd party CMD line tool that I am writing some POSH wrappers for. Most work fine. The problem I am having issues with is when an argument has a space in it. Below is an example. Some of the values have to have quotes around them. With spaces in the variable $Value3 it errors on me. An error that comes from the cl line tool I am using with a parse error. I have tried various scenarios such as using single quotes, removing the quotes all give the error. It is only when I take the space out that it works fine. If I bypass POSH and run  the command at the command line it works fine with the space as long as there are quotes around it. S that leads me to believe it is something with how POSH is passing the parameters along.

$Value1 = "ValueOne"
$Value2 = "ValueTwo"
$Value3 = "Value three"

$Params =  New-Object -TypeName System.Collections.ArrayList
$Params.Add('Arg1')
$Params.Add('Ag1=' + '"' + $Vaule1 + '"' )
$Params.Add('Arg2=' + '"' + $Value2 + '"')
$Params.Add('Arg3=' + '"' + $Value3 + '"')
$Params.Add('SESSIONID=' + $SessionID)

."c:\tools\MyTool.exe" $Params


It runs through several commands and most work just fine with how I have been doing it it is just those nagging spaces. any suggestions? Maybe a better way to pass command line arguments? I thought in order to pass a series of command along to a command line tool they had to be loaded into an array?

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles