1

I know this must be simple but I can't figure out how to do it. I have a string in a variable that is being read in via XML. The variable is called $software and its value is Java Flash Reader "Flash (IE)"

This is then launched from a command line later:

C:\Deployment\Ninite\NiniteOne.exe /select $xmlsoftware $installtype /remote file:"$NiniteTargets" $shortcuts $autoupdate /cachepath "$NiniteCache" $userinterface "$NiniteLog"

The command is breaking when it gets to the "Flash (IE)" portion. I think something is happening with the brackets being in that variable but I am unsure. Any help would be appreciated.

Trinitrotoluene
  • 1,388
  • 5
  • 20
  • 39

2 Answers2

1

First of all: Why delegate to cmd just for running a program? PowerShell is a shell, too:

blabla.exe /select $software /silent

But the problem is a little more complex than that, even with the complications of cmd's argument parsing removed:

PS> $software = 'Java Flash Reader "Flash (IE)"'
PS> .\echoargs.exe /select $software /silent
arg 1: /select
arg 2: Java Flash Reader Flash
arg 3: (IE)
arg 4: /silent

You can replace quotation marks in the value with \" to make it work, apparently:

PS> $software = $software -replace '"', '\"'
PS> .\echoargs.exe /select $software /silent
arg 1: /select
arg 2: Java Flash Reader "Flash (IE)"
arg 3: /silent
Joey
  • 344,408
  • 85
  • 689
  • 683
  • Fantastic idea - just tried it though and it still does exactly the same. It's almost like it is ignoring the quotation marks or ripping them out. – Trinitrotoluene Aug 01 '12 at 12:08
  • That still didn't work for me for some reason, I get the same error. The exact command I am running I will update in main post – Trinitrotoluene Aug 01 '12 at 12:37
  • You should probably debug this with something that outputs the arguments as they arrive in the called application. Without knowing the other values it's hard to see from here. My `echoargs` is `class E{static void Main(string[]args) {int i=1;foreach(var s in args){System.Console.WriteLine("arg {1}: {0}",args[i-1],i++);}}}`. The `file:"$NiniteTargets"` might be a candidate that could break things. PowerShell is a little picky about quotes embedded in arguments and usually you don't need to quote variables at all. – Joey Aug 01 '12 at 12:48
0

Try declaring $software like this:

$software = $('Java Flash Reader "Flash (IE)"')

The other option is to try declaring like this:

$software = "Java Flash Reader `"Flash `(IE`)`""

Adding the back tics to escape the ( and "

Nick
  • 4,302
  • 2
  • 24
  • 38