How to pass input variable from launch.json to tasks.json in vscode
Asked Answered
E

1

8

I can use input variables from launch.json in launch.json.

"configurations": [
  {
    ...
    "args": [${input:file_no}]
    "preLanuchTask": "runPreTasks"
    ...
  }
],
"inputs": [
  {
    "id": "file_no",
    "type": "promptString"
  }
]

Now, I want to get access to the same variable without entering input a second time in tasks.json.

{
  "version": "2.0.0",
  "tasks":[
    {
      "label": "runPreTasks",
      "type": "shell",
      "command": sh,
      "args": [
        "/path2script/scriptName.sh",
        "${input:file_no}"    // This does not work, without defining input again
      ]
    }
  ]
}

Is there a way to pass input variables from launch.json to tasks.json in vscode?

Electrocardiograph answered 2/9, 2021 at 10:38 Comment(0)
E
1

Following @rioV8 answer, I edited my json files as shown below:

launch.json:

"configurations": [
  {
    ...
    "args": [${input:file_no}]
    "preLanuchTask": "runPreTasks"
    ...
  }
],
"inputs": [
  {
    "id": "file_no",
    "type": "command",
    "command": "extension.commandvariable.promptStringRemember",
    "args": {
      "key": "lastnumber",
      "description": "Enter the number"
    }
  }
]

tasks.json:

{
  "version": "2.0.0",
  "tasks":[
    {
      "label": "runPreTasks",
      "type": "shell",
      "command": sh,
      "args": [
        "/path2script/scriptName.sh",
        "${input:file_no}"    
      ]
    }
  ]
  "inputs": [
    {
      "id": "file_no",
      "type": "command",
      "command": "extension.commandvariable.rememberPick",
      "args": { "key": "lastnumber" }
    }
  ]
}
Electrocardiograph answered 3/9, 2021 at 10:19 Comment(1)
Give credit where credit is due and mark as answer the @rioV8 response, not your own. Your answer won't work out of the box if not first reading the true answerer. You can always point out this post on the comment sections to indicate what you did after reading the real answer.Influence

© 2022 - 2024 — McMap. All rights reserved.