Use file input(stdin) in VS Code debug argument

Question:

I have a script that accepts multiple arguments and takes a file input(stdin) as one of the last argument. Tried debugging the script in VS Code debugger. But the file input arg is not working. The script doesn’t understand the fourth argument in the launch.json. here’s what I have in my launch.json file:

{
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args": [
                "arg1",
                "arg2",
                "arg3",
                "''",
                "<",
                "Path/to/file/test.json"
            ]
        }
    ]
}

I basically put the arguments the same way as I run in the console which is this-

python main.py arg1 arg2 arg3 '' < Path/to/file/test.json

Is there a different way vscode debugger takes an argument?

Asked By: saz

||

Answers:

python main.py arg1 arg2 arg3 '' < Path/to/file/test.json

When you type this command into your shell, your shell (whichever one it is) is probably interpreting the fourth argument to be an empty string and not actualy "''". I.e. what the shell gives to your program will be an empty string and not "''". I’m pretty sure that means that your fourth "args" value in your launch.json configuration is supposed to just be an empty JSON string ("") instead of a JSON string containing two single-quotes ("''").

Answered By: user