WSL

Running PowerShell or cmd from WSL Bash

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. Forgetting to escape can lead to errors, and in the worst case, strange code might be executed, which could be serious. So, from now on...

Shou Arisaka
1 min read
Nov 25, 2025

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

Share this article

Shou Arisaka Nov 25, 2025

🔗 Copy Links