0

I'm trying to pass the variable "foo" which contains the "bar" in the args field, but no syntax seems to work.

I've tried either for the syntax "${foo}" or "${env:foo}".

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "env": {
                "foo": "bar",
            },
            "args": [
                "${foo}", // output: \$\{foo\}
                "${env:foo}" // output: ""
            ]
        },
    ],
}
Aquila
  • 1
  • 1
  • Does this answer your question? [How do I add environment variables to launch.json in VSCode](https://stackoverflow.com/questions/29971572/how-do-i-add-environment-variables-to-launch-json-in-vscode) – ggeop Jan 19 '23 at 12:48
  • with the `args` property you can only use current environment variables, you are adding `foo` to the **new** environment, that does not exist for VSC – rioV8 Jan 19 '23 at 12:52
  • @rioV8: i'm using a python venv. i've set my env var in `activate` file `venv/bin/activate`, but it's still not passed as an argument – Aquila Jan 19 '23 at 13:11
  • because that is not the environment that is VSC environment. Look at the env vars in the terminal where you start VSC, that are the env vars that you can use in the `${env}` variable – rioV8 Jan 19 '23 at 14:43
  • @rioV8: thanks, i added my foo variable to the env variables of my terminal and called it on the args with `"${env:foo}"` and now it works. It's confusing to have an "env" property in the json file, – Aquila Jan 19 '23 at 16:08
  • you have to be aware which environment is active for the process that is executing, maybe the question will work if you escape the `$`: `"args:"["\$foo"]`, now you let the shell created by the task resolve the env var and that shell has the new environment varibles – rioV8 Jan 19 '23 at 16:37

0 Answers0