0

I have the following in my workspace settings.json file:

"terminal.integrated.env.osx": {
    "AUTH_TOKEN": "secret_XXXXXX"
}

However, when trying to pass this via a launch command (defined in launch.json):

    {
        "name": "Example: Query",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/examples/query.py",
        "args": [ "${env:AUTH_TOKEN}" ]
    }

The resulting command contains an empty string for the argument:

/usr/bin/env /.../.venv/bin/python /.../debugpy/launcher 58644 -- /.../examples/query.py ""

However, if I print the variable from within the script, it is set properly.

I believe there is an ordering issue, such that the launch.json commands are generated before the terminal environment is set up - resulting in empty vars. Any ideas how to propagate the env value to the command line?

Update: I have also tried using a .env file for the variables (rather than settings.json), but the result is the same.

2 Answers 2

1

Try using "env" in launch.json...

{
          "name": "Example: Query",
          "type": "python",
          "request": "launch",
          "program": "${workspaceFolder}/examples/query.py",
          "args": ["${AUTH_TOKEN}"], // using var from env on args
          "env": {
                "AUTH_TOKEN": "XXXX",
                "ENV2" : "XXX"
          }
            
}

you can use envs from file too

{
    // ...
    "args": ["${AUTH_TOKEN}"],
    "envFile": "${workspaceFolder}/local.env",
}

Sign up to request clarification or add additional context in comments.

3 Comments

Same result... The env vars are not resolved in the launch config args.
try both... declare in "env":{"AUTH_TOKEN":"XX"}" and using on args "args":["${AUTH_TOKEN}"] ( answer has been refreshed )
no dice... launch just escapes the variable reference. I've already guessed at many of these solutions, just looking for someone who knows of a workaround.
0

You can create a .env file, and then put the variable in there, and read it from the environmental variables in the program instead of it being an argument.

1 Comment

Yes, but that will change the behavior of the program, which is not desired. I appreciate the pointer, but still hoping there is a way to pass via command line args, which preserves the intent of the script. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.