1

I have a batch file which sets a variable using the following:

set "MyVariable=Test"

I have configured a task in tasks.json to run this batch file:

{
    "version": "2.0.0",
    "tasks": [{
        "label": "VariableTest",
        "command": "${workspaceFolder}/.vscode/VariableTest.bat",
        "args": [],
        "type": "shell"
    }]
}

How can I retrieve the value of this variable from my launch.json file? "VariableTest" is setup as a preLaunchTask for the launch configurations, and parameters in this configuration depend on this variable.

I am of course running Windows (10).

Thanks!

1
  • You could create another batch file from your first batchfile and then execute that batch file in another dependant task using the "dependsOn": ["firstTask"] option Commented Jun 16, 2020 at 13:57

1 Answer 1

3

This variable is set in a separate shell.

You need to store the value in a file and use an extension to retrieve the content.

Use

echo SomeText > c:\temp\VariableResult.txt

to store the variable value in a file.

You can use Command Variable and the command extension.commandvariable.file.content

An example launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File Args",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "args" : ["${input:variableResult}"],
      "preLaunchTask": "VariableTest"
    }
  ],
  "inputs": [
    {
      "id": "variableResult",
      "type": "command",
      "command": "extension.commandvariable.file.content",
      "args": {
        "fileName": "c:\\temp\\VariableResult.txt"
      }
    }
  ]
}

If the output file contains key-value pairs you can specify the key to use.

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

Comments

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.