1

Let's look at the code below

$SBK="0x1682CCD8 0x8A1A43EA 0xA532EEB6 0xECFE1D98"
./windows/nvflash/nvflash.exe --sbk 0x1682CCD8 0x8A1A43EA 0xA532EEB6 0xECFE1D98
./windows/nvflash/nvflash.exe --sbk "0x1682CCD8 0x8A1A43EA 0xA532EEB6 0xECFE1D98"
./windows/nvflash/nvflash.exe --sbk $SBK

I have define a string var $SBK and then I'm going to pass it for some app. The first process call is working properly. The second one fails and therefore application doesn't accepts quotes. But the third call is failed too with the same error. It seems that powershell passes quotes, those are causing errors. But how to eliminate them? Thanks beforehand.

Stan
  • 1,931
  • 16
  • 17

2 Answers2

1

Try doing

iex "./windows/nvflash/nvflash.exe --sbk $SBK"

Also, get echoargs.exe from PowerShell Community Extensions to see how args are passed from Powershell to commands etc.

manojlds
  • 290,304
  • 63
  • 469
  • 417
1

You should probably not use Invoke-Expression (see This Post from the PowerShell Team)

Instead, you can create an array of arguments, and then pass them using the call operator. See this post of mine on the subject for more details.

In your case, it would look something like this:

$SBKArgs="--sbk", "0x1682CCD8", "0x8A1A43EA", "0xA532EEB6", "0xECFE1D98"
$cmd = Get-Command ./windows/nvflash/nvflash.exe 
& $cmd $sbkargs

Hope this Helps

Start-Automating
  • 8,067
  • 2
  • 28
  • 47
  • Thanks for the link, but all the reasons that they give don't make any sense at all. It doesn't even give proper examples for those. And code injection? Seriously? We are not writing a website or something here. I think things have to be taken in context here. Powershell scripts are not avenues for "script injection". Slower? We are scripting anyway. If I want performance I will go with C# or something. Anyone needs performance for these things? Harder to maintain? I need example here. Complicates getting quote right? It is because of limitedness of Powershell that we want to do this. – manojlds Nov 09 '11 at 05:58
  • 1
    The basics of this are something that has been covered in many forums before: PowerShell has many of its own quoting rules and you use them all the time without thinking of it. Batch commands are a no-mans-land. They lack any of the consistentcy of PowerShell cmdlets. Invoke-Expression adds another layer of complication by stripping out some quotes as the expression is escaped, and another set when it's executed. It does allow for code injection, and you do not know if this will be used in a web application. – Start-Automating Nov 10 '11 at 02:25