Is it possible to pass arguments to a task in Visual Studio Code

前端 未结 3 1293
臣服心动
臣服心动 2020-12-25 11:39

Here\'s an example of my tasks.json:

{
  \"version\": \"0.1.0\",
  \"tasks\": [
    {
      \"taskName\": \"test\",
      \"suppressTaskName\":          


        
3条回答
  •  鱼传尺愫
    2020-12-25 12:01

    Here's what is working for me for now - using this to run a golang snippet with custom arguments. If you add a keyboard mapping to this, the process is very straightforward.

    So far tested this only under Windows - linux version is commented out for that reason

    {
            "label": "runwithargs",
            "type": "shell",
            "windows": {
                "options": {
                    "shell": {
                        "executable": "powershell.exe",
                        "args": [
                            "-NoProfile",
                            "-ExecutionPolicy",
                            "Bypass",
                            "-Command"
                        ]
                    }
                },
                "command": "",
                "args": [
                    { "value": "$cmdargs = read-host 'Enter command line arguments';", "quoting": "weak"},
                    { "value": "go run ${file} $cmdargs", "quoting": "weak"}
                ]
            },
            /*"linux": {
                "command": "echo 'Enter command line arguments: '; read cmdargs;",
                "args": [ "go run ${file} $cmdargs" ]                
            },*/          
            "presentation": {
                "panel": "dedicated",
                "focus": true
            }
        }
    

提交回复
热议问题