Skip to content

Conversation

Copy link

Copilot AI commented Dec 18, 2025

User reported inability to execute bash functions and commands in new Windows Terminal tabs from .bashrc, getting error 0x80070002. Documentation lacked clear examples for WSL command execution patterns.

Changes

  • Added "Executing commands in new tabs" section with platform-specific examples (Command Prompt, PowerShell, Linux/WSL)
  • WSL-specific guidance explaining why bash functions/aliases fail in new tabs and how to work around it
  • Practical patterns for common use cases: sourcing .bashrc, keeping tabs open with exec bash, running scripts

Example

The user's failing pattern:

wt.exe -w 0 new-tab -p "ubuntu-22.04" -c function_in_my_bashrc_file
# Error: 0x80070002 - bash functions aren't directly accessible

Corrected approach now documented:

function launch_my_project() {
    # Source .bashrc to access functions
    cmd.exe /c "wt.exe" -w 0 new-tab --title "Daemon" -p "Ubuntu-22.04" \
        bash -c "source ~/.bashrc && my_daemon_function && exec bash"
    
    # Direct command execution
    cmd.exe /c "wt.exe" -w 0 new-tab --title "Server" -p "Ubuntu-22.04" \
        bash -c "cd ~/project && npm start"
}

Key insights documented:

  • bash -c "command && exec bash" pattern to keep tabs open
  • Bash functions require sourcing .bashrc in new shell sessions
  • Alternative: extract logic to script files for direct execution
Original prompt

This section details on the original issue you should resolve

<issue_title>example needed to open new WT window and launch commands "within the new window"</issue_title>
<issue_description>### 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</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@learn-build-service-prod
Copy link

Learn Build status updates of commit 6bd4ed2:

✅ Validation status: passed

For more details, please refer to the build report.

Co-authored-by: mattwojo <7566797+mattwojo@users.noreply.github.com>
@learn-build-service-prod
Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod
Copy link

Learn Build status updates of commit d44de5f:

✅ Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md ✅Succeeded View

For more details, please refer to the build report.

Co-authored-by: mattwojo <7566797+mattwojo@users.noreply.github.com>
@learn-build-service-prod
Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod
Copy link

Learn Build status updates of commit 261f2b4:

✅ Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md ✅Succeeded View

For more details, please refer to the build report.

Co-authored-by: mattwojo <7566797+mattwojo@users.noreply.github.com>
@learn-build-service-prod
Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod
Copy link

Learn Build status updates of commit 22efa5a:

✅ Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md ✅Succeeded View

For more details, please refer to the build report.

Copilot AI changed the title [WIP] Add example for opening new WT window with commands Add examples for executing commands in new Windows Terminal tabs from WSL Dec 18, 2025
Copilot AI requested a review from mattwojo December 18, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants