This blog post describes a technique that you can use to open a new window to run a Windows Subsystem for Linux (WSL) command and close that window automatically afterwards. You can use a similar technique for Windows command lines.
If you do not already have a WSL shell window open, you can open a shell window, enter a command line, and close the window afterwards. Alternatively, you can:
- Press Ctrl+R
- Type wt wsl followed by the command line
- Press <Enter>
Ctrl+R opens the run dialog, wt.exe launches Windows Terminal that runs wsl.exe (bash.exe, the Windows Subsystem for Linux Bash shell) to invoke the remainder as a command line before closing the Windows Terminal window (unless an error occurs).
For example, to get the man page for the sort command:
Ctrl+R,wt wsl man sort,<Enter>
If you don’t mind using a Windows command prompt instead of Windows Terminal, you can omit wt:
Ctrl+R,wt wsl man sort,<Enter>
As a bonus, unless you disable this feature, the Windows run dialog keeps a history of the commands that you invoke.
For a Windows command line, you can achieve the equivalent by adding the /c argument to cmd.exe. For example:
Ctrl+R,cmd /c pause,<Enter>
oh and feel free to remove the earlier comment, and this one, after the fix.
LikeLike
I think you responded on the wrong blog or post? Or I don’t know what earlier comment you mean.
LikeLike