Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start window's terminal from CLI and pass in an executable command to run

I can start Windows Terminal with wt. I have read the Windows Terminal documentation on command-line arguments, and it just covers passing an argument for setting up terminal panes, not passing in actual executable commands.

For example, a minimal reproducible example: Requires Windows Terminal installed:

Open a CMD prompt in Windows and type:

dir | wt

This starts Windows Terminal, but it does not receive the dir command. How does one pass the executable command to Windows Terminal?

like image 973
run_the_race Avatar asked Jul 09 '20 23:07

run_the_race


People also ask

How do I Run an exe from command line arguments?

You can test command line arguments by running an executable from the "Command Prompt" in Windows or from the "DOS prompt" in older versions of Windows. You can also use command line arguments in program shortcuts, or when running an application by using Start -> Run. This will start notepad with a blank document.

How do I start WSL from command line?

To start using WSL, open up a PowerShell terminal and type wsl . If you've set up WSL correctly, you'll enter a bash terminal running on the WSL distro of choice. From here, you can run any Linux commands you wish.

How do I Run an executable in Windows Terminal?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.


Video Answer


1 Answers

Use

wt new-tab -p "Command Prompt" -d "%cd%" cmd /k dir
  • You can omit new-tab (it’s a default command).

  • Omitting -d "%cd%" seems to be equivalent to -d "%USERPROFILE%".

  • You can omit -p "Command Prompt" if your default profile is set to the cmd.exe profile. Check the wt settings in the following file (Windows):

    %LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
    

Try a more complex command than dir, for instance

wt new-tab -p "Command Prompt" -d "%cd%" cmd /k "dir & type "%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json""

Please check the How to pass commands into the shell opened in new Windows Terminal question as well.

like image 129
JosefZ Avatar answered Sep 21 '22 09:09

JosefZ