Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell task without environment variables. #72323

Closed
carlos-piloto opened this issue Apr 15, 2019 · 7 comments
Closed

Shell task without environment variables. #72323

carlos-piloto opened this issue Apr 15, 2019 · 7 comments
Assignees
Labels
info-needed Issue requires more information from poster tasks Task system issues

Comments

@carlos-piloto
Copy link

carlos-piloto commented Apr 15, 2019

  • VSCode Version: 1.33.0
  • OS Version: Windows 10 17134.706

We are using VSCode to build an IoT project for STM32 products using cmake. We need to build it using a toolchain and normally we can compile it from the cmd by using several environment variables with the different tools path.
We created several tasks to build and run the project, but the problem is that the cmd/powershell shell is launching VSCode does not have any environment variables.

For the moment we created a config variable in the settings to specify the root folder of all the compilation tools, but we do not think ois the best solution.

Steps to Reproduce:

  1. Run a task
  2. Try to read an environment variable by using: ${env:ENV_VAR_NAME} in the task or from the programe running in the shell.

You can see the images below of the winpty process that launch the shell:

image

image

You can see that the process is launched without the environment variables.

@vscodebot vscodebot bot added the tasks Task system issues label Apr 15, 2019
@alexr00
Copy link
Member

alexr00 commented Apr 15, 2019

duplicate of #72029
If you update to 1.33.1 you will have the fix.

@alexr00 alexr00 added the *duplicate Issue identified as a duplicate of another issue(s) label Apr 15, 2019
@vscodebot vscodebot bot closed this as completed Apr 15, 2019
@alexr00 alexr00 added info-needed Issue requires more information from poster and removed *duplicate Issue identified as a duplicate of another issue(s) labels Apr 15, 2019
@alexr00 alexr00 reopened this Apr 15, 2019
@microsoft microsoft deleted a comment from vscodebot bot Apr 15, 2019
@alexr00
Copy link
Member

alexr00 commented Apr 15, 2019

That other issue is about ${env:ENV_VAR_NAME} not expanding in tasks, not about no environment being given to the terminal. I can't reproduce that though. Can you try updating to 1.33.1 and running this task:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo path",
            "type": "shell",
            "command": "Write-Host '${env:PATH}'",
        }
    ]
}

@carlos-piloto
Copy link
Author

Hi @alexr00 ,

Indeed I updated the VSCode to 1.33.1 and I can access env variables right now ;-)

Thanks a lot for the quick response and support.

@alexr00 alexr00 closed this as completed Apr 15, 2019
@Clecius
Copy link

Clecius commented Apr 24, 2019

Cannot use additional environment variables in task.

VSCode Version: 1.33.1
OS: Windows_NT x64 6.1.7601

tasks.json

{
  "options": {
    "env": {
      "ENVAR": "VALUE"
    }
  },
  "tasks": [
    {
      "type": "shell",
      "label": "SHOWVAR",
      "command": "echo",
      "args": [
        "ENVAR[${env:ENVAR}] - OS[${env:OS}] / ENVAR[%ENVAR%] - OS[%OS%]"
      ],
      "problemMatcher": [],
    }
  ],
  "version": "2.0.0"
}

Terminal:

> Executing task: echo "ENVAR[] - OS[Windows_NT] / ENVAR[%ENVAR%] - OS[%OS%]" <
ENVAR[] - OS[Windows_NT] / ENVAR[VALUE] - OS[Windows_NT]

@alexr00
Copy link
Member

alexr00 commented Apr 26, 2019

That is correct! This needs to be better documented. Please see the new documentation here: microsoft/vscode-docs#2603

@idanpa
Copy link

idanpa commented Apr 28, 2019

@alexr00, thanks for this update of the documentation, but is there any plan to change this behavior of "env" in task.json?
See #47985 and #22374.

@alexr00
Copy link
Member

alexr00 commented Apr 29, 2019

#47985 is for overwriting env vars and #22374 is for global scope tasks only. There is no plan to change the behavior here. Feel free to open a feature request for it. However, it doesn't seem strictly necessary to expand env vars that are defined in the task in the task command like this. Since you are defining the value in the tasks.json, you already know the expanded value and you could easily just include the expanded value in the task command.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster tasks Task system issues
Projects
None yet
Development

No branches or pull requests

4 participants