batch-filecmdwindows-subsystem-for-linux

Create a script to open WSL2-Ubuntu and run some commands


I would like to create a script in Windows 11. When I click on the script, the following actions will be done:

Inspired by this answer I create VSCode.bat that contains the following lines:

ubuntu
ln -sf  /mnt/wslg/runtime-dir/wayland-* $XDG_RUNTIME_DIR/
SDL_VIDEODRIVER="wayland" code .

When I click on VSCode.bat, I only get

C:\Users\Akira\Desktop>ubuntu
root@DESKTOP:~#

This means that the remaining two commands have not been executed in Ubuntu terminal. Could you explain how to do so?


Solution

  • You can just add wsl before the command you want to run, for example

    wsl ln -sf  /mnt/wslg/runtime-dir/wayland-* $XDG_RUNTIME_DIR/ 
    wsl SDL_VIDEODRIVER="wayland" code .