MicrosoftDocs / terminal

Creative Commons Attribution 4.0 International
470 stars 177 forks source link

example needed to open new WT window and launch commands "within the new window" #744

Open surfaceowl opened 8 months ago

surfaceowl commented 8 months ago

Type of issue

Missing information

Feedback

Great docs on opening new windows, love it.

However there are not clear examples on how to open a new window and have commands executed within that window specifically from .bashrc, before moving onto my next WT command. Referring specifically to this page: # Windows Terminal command ref: https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=linux

Simple example - running Ubuntu 22.04, I have the following function defined in my .bashrc - I want it to open new tabs, and launch some processes in each tab.

function 1

opens multiple tabs needed to run project locally

function launch_nice_new_tabs_for_my_scripts() {
    wt.exe -w 0 new-tab --title window_01 --tabColor '#4d658d';
    wt.exe -w 0 new-tab --title window_02_client --tabColor '#468b76' -p "ubuntu-22.04-dev";
    wt.exe -w 0 new-tab --title window_03_daemon --tabColor '#7484a6' -p "ubuntu-22.04-dev";
    wt.exe -w 0 new-tab --title server --tabColor '#aa5f37' -p "ubuntu-22.04-dev";
    wt.exe focus-tab -t 1
}

function 2

opens multiple tabs needed to run project locally - but fails to launch any process

function launch_my_stuff_in_new_windows_v2() {

    wt.exe -w 0 new-tab --title window_01 --tabColor '#4d658d';
    wt.exe -w 0 new-tab --title window_02_client --tabColor '#468b76' -p "ubuntu-22.04-dev" -c function_in_my_bashrc_file;
    wt.exe -w 0 new-tab --title window_03_daemon --tabColor '#7484a6' -p "ubuntu-22.04-dev" -c another_function_in_my_bashrc;
    wt.exe -w 0 new-tab --title server --tabColor '#aa5f37' -p "ubuntu-22.04-dev" -c npm start;
    wt.exe focus-tab -t 1
}

function 2 -- launch_my_stuff_in_new_windows_v2 gives error:
error 2147942402 (0x80070002) when launching `function_in_my_bashrc_file']

All the other functions in my .bashrc work, and I'm able to run them directly from each of the new tabs I've been able to get a process launched in the original tab I called launch_my_stuff_in_new_windows from, but that's not the goal. I need separate processes launched in each tab.

ideas?

Page URL

https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=linux

Content source URL

https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=linux

Author

@nguyen-dows

Document Id

0d5d0fe3-01ef-66e8-263d-a0a7852ffa7a