Search code examples
batch-filewindows-10windows-subsystem-for-linux

How to pass arguments to WSL from a command prompt Batch File?


I am trying to make a Batch file that does the following:

  1. cd to a specific directory in my computer.
  2. Enter WSL Ubuntu.
  3. Run a binary file with some arguments.
  4. Close the command prompt terminal.

Ive written a little test batch file. It tries to do the specified actions. The only problem is that once it opens the bash terminal (in the same window) it won't perform the next line until I MANUALLY 'exit' out of WSL and then will try to run the './PESQ' line erroneusly (as it should be).

cd C:/users/jesus/desktop/source/audio
::desired path
bash
::this opens up an ubuntu terminal like session inside CMD
./PESQ
::this is the compiled file, besides, there are more arguments that need to be in that line, (+16000 speech.wav speech_bab_0dB.wav)
pause

When running the code I get the following output

C:\Users\jesus\Desktop\source\audio>bash jesusb@LAPTOP-08IGLCO1:/mnt/c/Users/jesus/Desktop/source/audio$

Once I type exit I get the following output

C:\Users\jesus\Desktop\source\audio>./PESQ
'.' is not recognized as an internal or external command, operable program or batch file.

C:\Users\jesus\Desktop\source\audio>pause
Press any key to continue . . .`

How can I give the ./PESQ +16000 speech.wav speech_bab_0dB.wav command to the bash terminal?


Solution

  • Instead of using bash, use the wsl command in your batch file:

    wsl ./PESQ +16000 speech.wav speech_bab_0dB.wav