![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Need info on how to escape double quotes Hi, We are developing PowerShell cmdlets and stumbled upon a problem with double quotes escaping. We are using CreateProcess method to start powershell process and run a nested powershell process in it. The arguments that we pass to powershell.exe are the following: ------------------------------- -NonInteractive -Command & {powershell.exe -NonInteractive -Command '& {"aaa" -eq "bbb"}' > "C:\output.txt"} ------------------------------- The idea is that we need the inner powershell to execute some user-defined script (in this case: “aaa” –eq “bbb”). The outer powershell is needed in order to redirect the output from the inner one in a file. But when we execute this we receive the following error in the output.txt file: ------------------------------- The term 'aaa' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. At line:1 char:7 + & {aaa <<<< -eq bbb} ------------------------------- We know that we need to escape the double quotes in some way, but we are unsure exactly how. It appears that the standard escaping rules do not apply in this case. Any help would be appreciated. P.S. Instead of using CreateProcess the same result can be reproduced when invoking the following line from powershell: ------------------------------- powershell.exe -NonInteractive -Command {powershell.exe -NonInteractive -Command '& {"aaa" -eq "bbb"}' > "C:\output.txt"} ------------------------------- |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Need info on how to escape double quotes Sorry I can't give you any developer help, I'm not one, but this works on CTP2 v2; I used the continuation character ` to avoid word wrapping, but it could be one line. Also used short names for parameters for the same reason. # CTP2 v2 powershell.exe -nonI -c {powershell.exe -nonI -c {& {"aaa" -eq "bbb"}` Quote: > C:\output.txt}} # -EncodedCommand parameter $cmd = 'powershell.exe -nonI -c {& {"aaa" -eq "bbb"} > C:\output.txt}' $encCmd = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($cmd)) powershell.exe -NonInteractive -encodedCommand $encCmd -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| Windows XP 32bit | Re: Need info on how to escape double quotes Thanks very much for your help. I'm using PowerShell 1.0 and encoding the command worked out perfectly. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Remove double quotes from a string | .NET General | |||
| shortcuts targetpath has double quotes and won't work? | PowerShell | |||
| Need info on how to escape double quotes | PowerShell | |||
| here-string with single and double quotes | PowerShell | |||
| Mix single and double quotes | PowerShell | |||