A brief introduction to a better way to run Windows commands like PowerShell and cmd.exe from WSL Bash in the Windows Linux command line environment using the Bash language.
Until now, I was doing it like powershell.exe ruby -e “puts ‘OK’”,
Well, as you might guess, this produces quite a few errors.
The cause is that the ruby -e “puts ‘OK’” part is functioning as a Bash script.
The longer the code following powershell.exe, the higher the error rate.
At least with this method, there’s no guarantee that you’ll get the same output as code executed in PowerShell. If you forget to escape, you’ll get errors, and in the worst case, strange code might be executed, which could be serious.
So, from now on, I’ll do it this way:
powershell.exe - <<'EOF'
ruby -e "puts 'OK'"
EOF