Is there a way to run a Bash command from CMD?

I want to run a command in CMD so it executes in Bash.

For example, open bash.exe "cd .." and this should open Bash, run cd... (I'm aware my example does not work).

Any thoughts and ideas?

1

1 Answer

I want to run a command in CMD so it executes in Bash.

Use wsl.exe:

Run Linux tools from a Windows command line

Run Linux binaries from the Windows Command Prompt (CMD or PowerShell) using wsl.exe <command>.

Binaries invoked in this way:

  • Use the same working directory as the current CMD or PowerShell prompt.
  • Run as the WSL default user.
  • Have the same Windows administrative rights as the calling process and terminal.

For example:

C:\temp> wsl ls -la
<- contents of C:\temp ->

The Linux command following wsl.exe is handled like any command run in WSL. Things such as sudo, piping, and file redirection work.

Note:

If you're running Creators Update or Anniversary Update, jump to the Creators/Anniversary Update section.

Source Windows interoperability with Linux | Microsoft Docs

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like