Issue with Activating Python Virtual Environment in VS 2022 Command Prompt via --tabCommand #21030

Closed
opened 2026-01-31 07:31:07 +00:00 by claunia · 21 comments
Owner

Originally created by @brupelo on GitHub (Jan 1, 2024).

Windows Terminal version

1.18.230526002-preview

Windows build number

Microsoft Windows [Version 10.0.19045.3803]

Other Software

No response

Steps to reproduce

Hi everyone,

I'm encountering an issue with activating a Python virtual environment within Windows Terminal, specifically when using the "Developer Command Prompt for Visual Studio 2022" profile. I've attempted various workarounds but haven't found a proper solution yet.

Below are the steps and details of the problem:

Creating the Environment:

mkdir python_project
cd python_project
virtualenv venv

Successful Activation (Without Virtual Environment):

If I spawn the "Developer Command Prompt for VS 2022" profile without additional arguments:

wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory "D:\python_project"

Everything works as expected, and the environment is configured properly. The profile content is as follows:

cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64

Issue with Virtual Environment Activation:

The problem arises when attempting to activate the Python virtual environment as a tabCommand. For instance:

wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory "D:\python_project" --tabCommand cmd /K "D:/python_project/venv/Scripts/activate.bat"
In this scenario, the Python virtual environment gets activated, but the compiler cl becomes unavailable.

I've been striving to find a workaround that allows for the activation of the Python virtual environment without losing access to the cl compiler. Any insights, suggestions, or potential solutions would be greatly appreciated.

Thank you for your time and assistance.

Best regards,

Expected Behavior

I'd expect a similar behaviour that spawning a profile and executing the --tabCommand manually


** Visual Studio 2022 Developer Command Prompt v17.6.5
** Copyright (c) 2022 Microsoft Corporation


D:\python_project>cmd /K "D:/python_project/venv/Scripts/activate.bat"

(venv) D:\python_project>where cl
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\cl.exe

as you can see in this case both vs & virtualenv will be available

Actual Behavior

The Python virtual environment gets activated but the compiler cl becomes unavailable.

Originally created by @brupelo on GitHub (Jan 1, 2024). ### Windows Terminal version 1.18.230526002-preview ### Windows build number Microsoft Windows [Version 10.0.19045.3803] ### Other Software _No response_ ### Steps to reproduce Hi everyone, I'm encountering an issue with activating a Python virtual environment within Windows Terminal, specifically when using the "Developer Command Prompt for Visual Studio 2022" profile. I've attempted various workarounds but haven't found a proper solution yet. Below are the steps and details of the problem: **Creating the Environment:** ``` mkdir python_project cd python_project virtualenv venv ``` **Successful Activation (Without Virtual Environment):** If I spawn the "Developer Command Prompt for VS 2022" profile without additional arguments: `wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory "D:\python_project" ` Everything works as expected, and the environment is configured properly. The profile content is as follows: `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64` **Issue with Virtual Environment Activation:** The problem arises when attempting to activate the Python virtual environment as a tabCommand. For instance: `wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory "D:\python_project" --tabCommand cmd /K "D:/python_project/venv/Scripts/activate.bat" ` In this scenario, the Python virtual environment gets activated, but the compiler cl becomes unavailable. I've been striving to find a workaround that allows for the activation of the Python virtual environment without losing access to the cl compiler. Any insights, suggestions, or potential solutions would be greatly appreciated. Thank you for your time and assistance. Best regards, ### Expected Behavior I'd expect a similar behaviour that spawning a profile and executing the --tabCommand manually ********************************************************************** ** Visual Studio 2022 Developer Command Prompt v17.6.5 ** Copyright (c) 2022 Microsoft Corporation ********************************************************************** D:\python_project>cmd /K "D:/python_project/venv/Scripts/activate.bat" (venv) D:\python_project>where cl C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\cl.exe as you can see in this case both vs & virtualenv will be available ### Actual Behavior The Python virtual environment gets activated but the compiler cl becomes unavailable.
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 07:31:08 +00:00
Author
Owner

@brupelo commented on GitHub (Jan 2, 2024):

Updated the issue... I've tried the latest version of wt 1.19.231113002-preview as I've realized a new --appendCommandLine flag has been added in #15822 , let's try:

cd d:\
mkdir python_project
cd python_project
virtualenv venv

And now let's give it a shot to the new flag to see if does the job:

wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project --appendCommandline d:\python_project\venv\Scripts\activate.bat
wt -w main new-tab --appendCommandLine -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project -- -Command d:\python_project\venv\Scripts\activate.bat
wt -w main new-tab --appendCommandLine -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project -- d:\python_project\venv\Scripts\activate.bat
wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project --appendCommandLine d:\python_project\venv\Scripts\activate.bat              
wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project --appendCommandLine cmd /k d:\python_project\venv\Scripts\activate.bat
wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project
wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project -- --appendCommandLine cmd /k d:\python_project\venv\Scripts\activate.bat
wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project --appendCommandLine "d:\python_project\venv\Scripts\activate.bat"

Mmmm, none of the above attempts did work and some of them lead to crashes, probably just me not understanding properly the syntax of that flag so let's take 1 step back and start with the basics:

If I try the basic command provided in the docs:

wt --appendCommandLine -p PowerShell -- -Command "where cl && pause"

it works and i can see the "Press Enter to continue" although i don't see any output coming from where cl... now let's do the same with the vs2022 profile...

wt --appendCommandLine -p Developer Command Prompt for VS 2022 -- -Command pause

In this case I don't see the "Press Enter to continue" anymore...

Differences between the powershell and vs2022 profiles is the first one spawning pwsh.exe directly and the later cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64

Anyway, this is clearly just me not knowing what I'm doing because I'm not sure how this flag works... if someone know how to accomplish this task to enable a virtualenv on the vs2022 profile please share.

Thanks in advance!

@brupelo commented on GitHub (Jan 2, 2024): Updated the issue... I've tried the latest version of wt 1.19.231113002-preview as I've realized a new --appendCommandLine flag has been added in #15822 , let's try: ``` cd d:\ mkdir python_project cd python_project virtualenv venv ``` And now let's give it a shot to the new flag to see if does the job: ``` wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project --appendCommandline d:\python_project\venv\Scripts\activate.bat wt -w main new-tab --appendCommandLine -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project -- -Command d:\python_project\venv\Scripts\activate.bat wt -w main new-tab --appendCommandLine -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project -- d:\python_project\venv\Scripts\activate.bat wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project --appendCommandLine d:\python_project\venv\Scripts\activate.bat wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project --appendCommandLine cmd /k d:\python_project\venv\Scripts\activate.bat wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project -- --appendCommandLine cmd /k d:\python_project\venv\Scripts\activate.bat wt -w main new-tab -p "Developer Command Prompt for VS 2022" --startingDirectory d:\python_project --appendCommandLine "d:\python_project\venv\Scripts\activate.bat" ``` Mmmm, none of the above attempts did work and some of them lead to crashes, probably just me not understanding properly the syntax of that flag so let's take 1 step back and start with the basics: If I try the basic command provided in the docs: `wt --appendCommandLine -p PowerShell -- -Command "where cl && pause"` it works and i can see the "Press Enter to continue" although i don't see any output coming from `where cl`... now let's do the same with the vs2022 profile... `wt --appendCommandLine -p Developer Command Prompt for VS 2022 -- -Command pause` In this case I don't see the "Press Enter to continue" anymore... Differences between the powershell and vs2022 profiles is the first one spawning `pwsh.exe` directly and the later `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64` Anyway, this is clearly just me not knowing what I'm doing because I'm not sure how this flag works... if someone know how to accomplish this task to enable a virtualenv on the vs2022 profile please share. Thanks in advance!
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

this is a profile command seems to work for me.

"C:\Users\james\AppData\Local\Microsoft\WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe\pwsh.exe" -NoExit -Command c:\temp\test_venv\Scripts\Activate.ps1

image
@jamespack commented on GitHub (Jan 8, 2024): this is a profile command seems to work for me. "C:\Users\james\AppData\Local\Microsoft\WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe\pwsh.exe" -NoExit -Command c:\temp\test_venv\Scripts\Activate.ps1 <img width="878" alt="image" src="https://github.com/microsoft/terminal/assets/2086722/bc489474-8af2-4b4c-bcfe-d86b3dab80b7">
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

{
                "altGrAliasing": true,
                "antialiasingMode": "grayscale",
                "closeOnExit": "automatic",
                "commandline": "\"C:\\Users\\james\\AppData\\Local\\Microsoft\\WindowsApps\\Microsoft.PowerShell_8wekyb3d8bbwe\\pwsh.exe\" -NoExit -Command c:\\temp\\test_venv\\Scripts\\Activate.ps1",
                "cursorShape": "bar",
                "font": 
                {
                    "size": 12.0
                },
                "guid": "{f259d0ac-671a-427f-a511-3716ee8517e9}",
                "hidden": false,
                "historySize": 9001,
                "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
                "name": "venv",
                "padding": "8, 8, 8, 8",
                "snapOnInput": true,
                "startingDirectory": "c:\\temp\\test_venv"
            }
        ]

The json for the profile if you are interested.

@jamespack commented on GitHub (Jan 8, 2024): ```json { "altGrAliasing": true, "antialiasingMode": "grayscale", "closeOnExit": "automatic", "commandline": "\"C:\\Users\\james\\AppData\\Local\\Microsoft\\WindowsApps\\Microsoft.PowerShell_8wekyb3d8bbwe\\pwsh.exe\" -NoExit -Command c:\\temp\\test_venv\\Scripts\\Activate.ps1", "cursorShape": "bar", "font": { "size": 12.0 }, "guid": "{f259d0ac-671a-427f-a511-3716ee8517e9}", "hidden": false, "historySize": 9001, "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png", "name": "venv", "padding": "8, 8, 8, 8", "snapOnInput": true, "startingDirectory": "c:\\temp\\test_venv" } ] ``` The json for the profile if you are interested.
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

I lied. Just realized you wanted both environments.. this worked for me.

            {
                "altGrAliasing": true,
                "antialiasingMode": "grayscale",
                "closeOnExit": "automatic",
                "commandline": "powershell.exe -NoExit -Command \"&{Import-Module \"\"\"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"\"\"; Enter-VsDevShell 1b380b52 -SkipAutomaticLocation -DevCmdArguments \"\"\"-arch=x64 -host_arch=x64\"\"\"; c:\\temp\\test_venv\\Scripts\\Activate.ps1}\"",
                "cursorShape": "bar",
                "font": 
                {
                    "size": 12.0
                },
                "guid": "{f259d0ac-671a-427f-a511-3716ee8517e9}",
                "hidden": false,
                "historySize": 9001,
                "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
                "name": "venv",
                "padding": "8, 8, 8, 8",
                "snapOnInput": true,
                "startingDirectory": "c:\\temp\\test_venv"
            }


image
@jamespack commented on GitHub (Jan 8, 2024): I lied. Just realized you wanted both environments.. this worked for me. ```json { "altGrAliasing": true, "antialiasingMode": "grayscale", "closeOnExit": "automatic", "commandline": "powershell.exe -NoExit -Command \"&{Import-Module \"\"\"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"\"\"; Enter-VsDevShell 1b380b52 -SkipAutomaticLocation -DevCmdArguments \"\"\"-arch=x64 -host_arch=x64\"\"\"; c:\\temp\\test_venv\\Scripts\\Activate.ps1}\"", "cursorShape": "bar", "font": { "size": 12.0 }, "guid": "{f259d0ac-671a-427f-a511-3716ee8517e9}", "hidden": false, "historySize": 9001, "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png", "name": "venv", "padding": "8, 8, 8, 8", "snapOnInput": true, "startingDirectory": "c:\\temp\\test_venv" } ``` <img width="856" alt="image" src="https://github.com/microsoft/terminal/assets/2086722/25d6305c-2ef5-48dc-92c0-b3629c6f3afc">
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

You can then call it like this and get both environments.
wt -w main new-tab -p "venv" --startingDirectory c:\temp\test_venv

@jamespack commented on GitHub (Jan 8, 2024): You can then call it like this and get both environments. ` wt -w main new-tab -p "venv" --startingDirectory c:\temp\test_venv `
Author
Owner

@brupelo commented on GitHub (Jan 8, 2024):

@jamespack Thank you for addressing this! Once I'm back home, I'll test your solution using 'cmd' instead of PowerShell to confirm its functionality. I anticipate it should work without any issues. Appreciate your effort on this, it's really impressive!

@brupelo commented on GitHub (Jan 8, 2024): @jamespack Thank you for addressing this! Once I'm back home, I'll test your solution using 'cmd' instead of PowerShell to confirm its functionality. I anticipate it should work without any issues. Appreciate your effort on this, it's really impressive!
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

for batch it would be something like this

cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_venv\scripts\activate.bat

@jamespack commented on GitHub (Jan 8, 2024): for batch it would be something like this ` cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_venv\scripts\activate.bat `
Author
Owner

@brupelo commented on GitHub (Jan 8, 2024):

@jamespack Ah, nice, yeah, I've realized now that your previous attempt would use PowerShell syntax, which is cool. So, I suppose that one would enable the virtual environment, and where python should point out to c:\temp\test_venv\scripts\python.exe, right? Hmm, this is a bit strange; I have a feeling I might have tried that approach in one of my numerous attempts, but perhaps I missed something specific. I'll give it another shot later on and see if I can figure it out and report back the results.

@brupelo commented on GitHub (Jan 8, 2024): @jamespack Ah, nice, yeah, I've realized now that your previous attempt would use PowerShell syntax, which is cool. So, I suppose that one would enable the virtual environment, and `where python` should point out to `c:\temp\test_venv\scripts\python.exe`, right? Hmm, this is a bit strange; I have a feeling I might have tried that approach in one of my numerous attempts, but perhaps I missed something specific. I'll give it another shot later on and see if I can figure it out and report back the results.
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

I'd setup a profile with that as the command. Then you can call it using simple wt command shown earlier

@jamespack commented on GitHub (Jan 8, 2024): I'd setup a profile with that as the command. Then you can call it using simple wt command shown earlier
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

Btw. Tested and worked. Let me know how you make out

@jamespack commented on GitHub (Jan 8, 2024): Btw. Tested and worked. Let me know how you make out
Author
Owner

@brupelo commented on GitHub (Jan 8, 2024):

Ok, let's give it a shot, here's the steps I've followed:

  1. Open a new terminal tab, create virtualenv & check it works
mkdir c:\temp && cd temp && virtualenv test_env
test_env\Scripts\activate.bat
where python

(test_env) c:\temp>where python
C:\temp\test_env\Scripts\python.exe
  1. I create the profile you posted like this
            {
                "commandline": "cmd.exe /k \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\VsDevCmd.bat\" -startdir=none -arch=x64 -host_arch=x64 && c:\\temp\\test_env\\scripts\\activate.bat",
                "guid": "{7c7f4437-1084-45fe-9d00-32694e025b6e}",
                "hidden": false,
                "name": "venv"
            }

I've created the profile using the UI, here's how it looks (rather than copy/pasting in the settings.json)

image

  1. Then I open a fresh wt process and I test it out

wt -w main new-tab -p "venv" --startingDirectory c:\temp\test_venv

and for some reason I'll get a crash

[error 2147942667 (0x8007010b) when launching `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_env\scripts\activate.bat']
Could not access starting directory "c:\temp\test_venv"

In any case, just to make sure we're on the same wave, the main goal of this thread is to figure out how to activate a virtualenv with vs2022 in a "parametrized" way... meaning I could spin up any virtualenv from a custom plugin from my IDe, ie: vscode, sublime, etc etc... Although not sure if right now it's possible to parametrize custom profiles? I mean, that'd be pretty cool tbh 😁

@jamespack Anyway, leaving the main goal aside and focusing in your attempt... probably just me being dummy, I'll continue testing in the meantime, not sure what that error means because that dir definitely exists ls c:\temp\test_env && echo %errorlevel is 0

@brupelo commented on GitHub (Jan 8, 2024): Ok, let's give it a shot, here's the steps I've followed: 1) Open a new terminal tab, create virtualenv & check it works ``` mkdir c:\temp && cd temp && virtualenv test_env test_env\Scripts\activate.bat where python (test_env) c:\temp>where python C:\temp\test_env\Scripts\python.exe ``` 2) I create the profile you posted like this ``` { "commandline": "cmd.exe /k \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\VsDevCmd.bat\" -startdir=none -arch=x64 -host_arch=x64 && c:\\temp\\test_env\\scripts\\activate.bat", "guid": "{7c7f4437-1084-45fe-9d00-32694e025b6e}", "hidden": false, "name": "venv" } ``` I've created the profile using the UI, here's how it looks (rather than copy/pasting in the settings.json) ![image](https://github.com/microsoft/terminal/assets/18058492/65a5e1ef-7cac-4235-b40f-b37af6249db3) 3) Then I open a fresh wt process and I test it out `wt -w main new-tab -p "venv" --startingDirectory c:\temp\test_venv` and for some reason I'll get a crash ``` [error 2147942667 (0x8007010b) when launching `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_env\scripts\activate.bat'] Could not access starting directory "c:\temp\test_venv" ``` In any case, just to make sure we're on the same wave, the main goal of this thread is to figure out how to activate a virtualenv with vs2022 in a "parametrized" way... meaning I could spin up any virtualenv from a custom plugin from my IDe, ie: vscode, sublime, etc etc... Although not sure if right now it's possible to parametrize custom profiles? I mean, that'd be pretty cool tbh 😁 @jamespack Anyway, leaving the main goal aside and focusing in your attempt... probably just me being dummy, I'll continue testing in the meantime, not sure what that error means because that dir definitely exists `ls c:\temp\test_env && echo %errorlevel` is 0
Author
Owner

@zadjii-msft commented on GitHub (Jan 8, 2024):

From the wt command you're using:

--startingDirectory c:\temp\test_venv

Looks like that's a typo ☺️ Try again with --startingDirectory c:\temp\test_env

@zadjii-msft commented on GitHub (Jan 8, 2024): From the `wt` command you're using: > `--startingDirectory c:\temp\test_venv` Looks like that's a typo ☺️ Try again with `--startingDirectory c:\temp\test_env`
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):


[error 2147942667 (0x8007010b) when launching `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_env\scripts\activate.bat']

Could not access starting directory "c:\temp\test_venv"

The starting directory has to exist. You are using the directory where I was doing my testing which very likely doesn't exist. What you're looking for probably not supported though I can't say for sure. You'd need a way to tell terminal to create the directory if it doesn't exist so the commands work.

@jamespack commented on GitHub (Jan 8, 2024): > ``` > > [error 2147942667 (0x8007010b) when launching `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_env\scripts\activate.bat'] > > Could not access starting directory "c:\temp\test_venv" > > ``` > > The starting directory has to exist. You are using the directory where I was doing my testing which very likely doesn't exist. What you're looking for probably not supported though I can't say for sure. You'd need a way to tell terminal to create the directory if it doesn't exist so the commands work.
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

If you are ok with the directory at least existing before hand you could still pull it off. You would just have to add another command to the command line (off the top of my head) cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && python -m venv whateverTheDirectoryIs && whateverTheDirectoryIs\scripts\activate.bat

Of course this assumes that python is on the path.

Perhaps if you own the code for the plugin you could create the directory before hand and then run the parameterized wt command.

@jamespack commented on GitHub (Jan 8, 2024): If you are ok with the directory at least existing before hand you could still pull it off. You would just have to add another command to the command line (off the top of my head) `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && python -m venv whateverTheDirectoryIs && whateverTheDirectoryIs\scripts\activate.bat` Of course this assumes that python is on the path. Perhaps if you own the code for the plugin you could create the directory before hand and then run the parameterized wt command.
Author
Owner

@jamespack commented on GitHub (Jan 8, 2024):

From the wt command you're using:

--startingDirectory c:\temp\test_venv

Looks like that's a typo ☺️ Try again with --startingDirectory c:\temp\test_env

Yep thats it in this case. Good call.

@jamespack commented on GitHub (Jan 8, 2024): > From the `wt` command you're using: > > > `--startingDirectory c:\temp\test_venv` > > Looks like that's a typo ☺️ Try again with `--startingDirectory c:\temp\test_env` Yep thats it in this case. Good call.
Author
Owner

@brupelo commented on GitHub (Jan 8, 2024):

@zadjii-msft Ha! Awesome, that call was genius 😂 ... moral of the story? always copy/paste directories from the log errors... I've been able to realize now the exit code of ls would be 2

Fast question, do you guys intend to add parametrization per profile? Would that make any sense? Before when James shared his profile I had this idea of how cool would be having a centralized repo, marketplace, artifactory of parametrized "profiles" ready to use & share 😋

Perhaps if you own the code for the plugin you could create the directory before hand and then run the parameterized wt command.

Yeah, I do... here's how the current invocation looks like:

{ "command": "zebra_wt_run", "keys": ["ctrl+shift+n"], "args": { "paths": [], "mode": "profiles", "cmd": "wt -w main -p \"{item}\" --startingDirectory {cwd}" } },

As you can see when i press a shortcut I'll be able to pick up the available profiles of wt in my text editor and I'll spawn wt on a given startingDirectory... I guess I could check or making sure the requirements of a given profile are fullfilled per directory but that'd require me to know upfront the internals of the existing profiles... I'll think about it. I mean, you can't assume all repos will use a hardcoded venv, I've got repos with few venvs, multiple python distributions, etc etc...

Anyway, cool stuff guys, quite a bit of progress on this one, thanks a mill!

@brupelo commented on GitHub (Jan 8, 2024): @zadjii-msft Ha! Awesome, that call was genius 😂 ... moral of the story? always copy/paste directories from the log errors... I've been able to realize now the exit code of ls would be 2 Fast question, do you guys intend to add parametrization per profile? Would that make any sense? Before when James shared his profile I had this idea of how cool would be having a centralized repo, marketplace, artifactory of parametrized "profiles" ready to use & share 😋 > Perhaps if you own the code for the plugin you could create the directory before hand and then run the parameterized wt command. Yeah, I do... here's how the current invocation looks like: { "command": "zebra_wt_run", "keys": ["ctrl+shift+n"], "args": { "paths": [], "mode": "profiles", "cmd": "wt -w main -p \"{item}\" --startingDirectory {cwd}" } }, As you can see when i press a shortcut I'll be able to pick up the available profiles of wt in my text editor and I'll spawn wt on a given startingDirectory... I guess I could check or making sure the requirements of a given profile are fullfilled per directory but that'd require me to know upfront the internals of the existing profiles... I'll think about it. I mean, you can't assume all repos will use a hardcoded venv, I've got repos with few venvs, multiple python distributions, etc etc... Anyway, cool stuff guys, quite a bit of progress on this one, thanks a mill!
Author
Owner

@brupelo commented on GitHub (Jan 9, 2024):

@zadjii-msft , @jamespack Hey guys, I've spent more time to see if I'd able to accomplish and close this issue but I'm still struggling... could you please take a look to below attempts?

  1. wt -w main new-tab -- cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_env\Scripts\activate.bat

if I use that one it'll execute the cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 block in the new-tab but then the c:\temp\test_env\Scripts\activate.bat part will be executed in the current terminal, which it's not what i want, here's how it looks like

image

The idea is being able to run the whole command cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_env\Scripts\activate.bat in the new tab.

  1. Then I've tried:
  • wt -w main new-tab -- "cmd. exe /k \"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat\" -startdi r=none -arch=x64 -host_arch=x64 && \"c:\temp\test_env\Scripts\activate.bat\""

but that'll lead to error 2147942402 (0x80070002)

  1. Finally I've also tried without -- to see if that'd make a dfifference (after new-tab), ie: wt -w main new-tab cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && "c:\temp\test_env\Scripts\activate.bat" but that won't work neither.

Also, it's important when trying these commands to make sure you spawn it from a root clean wt process where you didn't activate any virtualenv, otherwise it may give the right impression of working because the context inheritance of parent-child processes.

Thanks in advance.

@brupelo commented on GitHub (Jan 9, 2024): @zadjii-msft , @jamespack Hey guys, I've spent more time to see if I'd able to accomplish and close this issue but I'm still struggling... could you please take a look to below attempts? 1) `wt -w main new-tab -- cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_env\Scripts\activate.bat` if I use that one it'll execute the `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64` block in the new-tab but then the `c:\temp\test_env\Scripts\activate.bat` part will be executed in the current terminal, which it's not what i want, here's how it looks like ![image](https://github.com/microsoft/terminal/assets/18058492/77fd988e-d46a-47d6-98b4-ff6d622da011) The idea is being able to run the whole command `cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && c:\temp\test_env\Scripts\activate.bat` in the new tab. 2) Then I've tried: - `wt -w main new-tab -- "cmd. exe /k \"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat\" -startdi r=none -arch=x64 -host_arch=x64 && \"c:\temp\test_env\Scripts\activate.bat\""` but that'll lead to `error 2147942402 (0x80070002)` 3) Finally I've also tried without `--` to see if that'd make a dfifference (after new-tab), ie: `wt -w main new-tab cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 && "c:\temp\test_env\Scripts\activate.bat"` but that won't work neither. Also, it's important when trying these commands to make sure you spawn it from a root clean wt process where you didn't activate any virtualenv, otherwise it may give the right impression of working because the context inheritance of parent-child processes. Thanks in advance.
Author
Owner

@brupelo commented on GitHub (Jan 9, 2024):

Also, it's important when trying these commands to make sure you spawn it from a root clean wt process where you didn't activate any virtualenv, otherwise it may give the right impression of working because the context inheritance of parent-child processes.

Just to clarify here, make sure where python won't give you the path of c:\temp\test_env\Scripts\python.exe and the virtualenv is not already activated... otherwise it'll give the wrong impression that the wt command works while in reality is just executing the vs batch in the new tab while the virtualenv activation is being executed in the parent wt window.

@brupelo commented on GitHub (Jan 9, 2024): > Also, it's important when trying these commands to make sure you spawn it from a root clean wt process where you didn't activate any virtualenv, otherwise it may give the right impression of working because the context inheritance of parent-child processes. Just to clarify here, make sure `where python` won't give you the path of c:\temp\test_env\Scripts\python.exe and the virtualenv is not already activated... otherwise it'll give the wrong impression that the wt command works while in reality is just executing the vs batch in the new tab while the virtualenv activation is being executed in the parent wt window.
Author
Owner

@zadjii-msft commented on GitHub (Jan 9, 2024):

I think part of the issue you're running into here is when you run

wt -- foo && bar

in command prompt, you've got to deal now with CMD's command escaping. So CMD is gonna get the first crack at parsing that commandline, and CMD will break that internally into wt -- foo, &&, bar. (Without looking it up, ) I think that the escape character for CMD is something silly like ^, so wt -- foo ^&^& bar may be closer to what you want.

Or more elaborately,

wt -w main nt -- cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 ^&^& c:\temp\test_env\Scripts\activate.bat
@zadjii-msft commented on GitHub (Jan 9, 2024): I think part of the issue you're running into here is when you run ``` wt -- foo && bar ``` in command prompt, you've got to deal now with CMD's command escaping. So CMD is gonna get the first crack at parsing that commandline, and CMD will break that internally into `wt -- foo`, `&&`, `bar`. (Without looking it up, ) I think that the escape character for CMD is something silly like `^`, so `wt -- foo ^&^& bar` may be closer to what you want. Or more elaborately, ``` wt -w main nt -- cmd.exe /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 ^&^& c:\temp\test_env\Scripts\activate.bat ```
Author
Owner

@jamespack commented on GitHub (Jan 9, 2024):

Interesting

@jamespack commented on GitHub (Jan 9, 2024): Interesting
Author
Owner

@brupelo commented on GitHub (Jan 9, 2024):

@zadjii-msft Wow 😂 ... that's exactly the answer I've been looking for the past months, it works like a charm... I was so obsessed about finding the right commands of wt that I wasn't even considering how cmd would parse arguments at all.

I'll leave some links for future references:

It'd be interesting to find cmd's grammar or proper official docs though.

Anyway guys, thanks a mill for all your help, hope this issue will help anybody else as well. Still thinking about the concept of parametrized profiles would be quite an interesting feature to consider.

@brupelo commented on GitHub (Jan 9, 2024): @zadjii-msft Wow 😂 ... that's exactly the answer I've been looking for the past months, it works like a charm... I was so obsessed about finding the right commands of wt that I wasn't even considering how `cmd` would parse arguments at all. I'll leave some links for future references: - https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts - https://ss64.com/nt/ - https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments?view=msvc-170 It'd be interesting to find cmd's grammar or proper official docs though. Anyway guys, thanks a mill for all your help, hope this issue will help anybody else as well. Still thinking about the concept of parametrized profiles would be quite an interesting feature to consider.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21030