Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The call operator '&amp;' is unnecessary in this case. It is used to invoke a command in a new scope. This is typically used to invoke a command specified by a string or scriptblock. It also has the side benefit that any variables created in say a PowerShell script are discarded after the command finishes and the scope goes away.</p> <p>However since the cmd is an EXE it executes in a completely different process. FWIW, you get similar output directly from cmd.exe:</p> <pre><code>&gt; cmd "/c echo foo" foo" </code></pre> <p>So the extra quote on the end is a cmd.exe issue. Typically you need to keep the command separate from the parameters when PowerShell is doing the parsing to invoke the command e.g.</p> <pre><code>45&gt; &amp; { $foo = "foo" } 46&gt; $foo # Note that $foo wasn't found - it went away with the scope 47&gt; . { $foo = "foo" } # dotting executes in the current scope 48&gt; $foo foo </code></pre> <p>The notable exception here is that Invoke-Expression behaves like an "evaluate this string" function. Use with care, <em>especially</em> if the user provides the string. Your day could suck if they provided "ri C:\ -r".</p> <p>In this case, as others have suggested I would pull the /c out of the string $param string and specify it e.g.:</p> <pre><code>cmd /c $param </code></pre> <p>Or use Invoke-Expression but use with care. BTW when you are trying to debug issues with sending arguments to EXE from PowerShell, check out the echoargs utility in PowerShell Community Extensions (<a href="http://pscx.codeplex.com" rel="noreferrer">http://pscx.codeplex.com</a>). It is very handy:</p> <pre><code>49&gt; $param = "/c echo foo" 50&gt; echoargs $param Arg 0 is &lt;/c echo foo&gt; </code></pre> <p>This shows that cmd.exe receives "/c echo foo" as a <em>single</em> argument. "/c" should be a separate argument from "echo foo" (the command to execute).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload