skip to Main Content

I am debugging my code using a launch.json file. I have a long list of command line arguments:

            "args": [
                "-i", "inputfile",
                "-o", "outputfile",
                "--option", "do_stuff",
                "--very-long-option", "do_some_serious_stuff",
                ...
            ]

It works well. But now I would like to run the same program with the same arguments using command prompt:

my_prog -i inputfile -o outputfile --option do_stuff --very-long-option do_some_serious_stuff ...

I can generate this command line manually by editing the data taken from the launch.json file, but it’s time-consuming and error-prone. How can I make VSCode print this command line for me each time I debug my program?

I tried adding the following to my tasks.json file:

        {
            "label": "echo_cmd_line",
            "command": "echo",
            "args": ["args are", "${args}"],
            "type": "shell"
        },

and the following to my launch.json file:

        "preLaunchTask": "echo_cmd_line",

but it outputs just args are. Not sure I can access arguments in this way.

How can I make it work?

2

Answers


  1. Chosen as BEST ANSWER

    This currently seems to be impossible.

    As noted by this answer, this feature was requested 7 years ago but not implemented yet, so probably not deemed important enough.


  2. perhaps adding something like this —
    thanks to https://github.com/microsoft/vscode/issues/201785

    –in launch.json

    "preLaunchTask": "echo_cmd_line",
    "preLaunchTaskInputs": {
      "LaunchArgs": "${args}"
    }
    

    –in tasks.json

    "args": ["args are", "${LaunchArgs}"],
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search