Passing calculated paths with spaces

In the latest drop of PSCX we've update EchoArgs.exe to also show the entire command line as the receiving app sees it. In this case, you get:

14 >  echoargs $path $path2
Arg 0 is c:\program files" c:\program
Arg 1 is files\fred2"

Command line:
"C:\Users\Keith\Documents\WindowsPowerShell\Modules\Pscx\Apps\EchoArgs.exe"  "c:\program files\" "c:\program files\fred2
\"

It would seem that the \" is causing the trailing double quote to be escaped somewhere. BTW the same happens in CMD.exe from what I can tell. If you modified your paths to remove the trailing slash (or if you used forward slashes), this wouldn't happen.

20 >  $path = "c:\program files"
21 >  $path2 = "c:\program files\fred2"
22 >  echoargs $path $path2
Arg 0 is c:\program files
Arg 1 is c:\program files\fred2

Command line:
"C:\Users\Keith\Documents\WindowsPowerShell\Modules\Pscx\Apps\EchoArgs.exe"  "c:\program files" "c:\program files\fred2"

If you get these paths from somewhere else, you can remove the trailing backslash like so:

$path = $path.TrimEnd("\")

You need to enclose your result strings in single quotes inside the scope of the execution:

echoargs "'$path'" "'$path2'"

This will pass them to the called application delimited inside single quotes, but since the entire string is still in double quotes your parameter will be expanded correctly.