Escape characters when executing powershell command in batch script
问题 I want to execute powershell command and put it in batch variable The command: for /f "delims=" %%i in ('powershell ^(Get-ChildItem ""\dir\"" -Name | sort-object {\[regex\]::Replace^($_,^'\d+^',{$args\[0\].Value.PadLeft^(20^)}^)} | select -last 1^) ') do set output=%%i It can't be executed due special character. In addition, I can't pause the window so it closes before I can see what is the problem. I think the problem is with the pipe "|", because the following command does work(the part