-1

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?

starball
  • 20,030
  • 7
  • 43
  • 238
saz
  • 955
  • 5
  • 15
  • 26
  • I'd recommend using argparse over input-redirection – OneCricketeer Feb 27 '23 at 21:52
  • 1
    `<` isn't an argument to your executable; instead, it's a shell instruction (telling the shell to replace stdin with an open file handle on `test.json` before your executable is started at all). For the same reason, `test.json` _also_ isn't passed to your program as an argument. (This is all unless VS Code does magic to try to emulate a shell and enact redirections, but for sanity's sake I'd hope it wouldn't) – Charles Duffy Feb 27 '23 at 21:59
  • @CharlesDuffy I was thinking the exact same thing as you... and then I saw [Use input (stdin) in debug console VScode](/q/64786161/11107541). Seems there's no magic- just passing to the underlying shell (I _think_). [docs](https://code.visualstudio.com/docs/editor/debugging#_redirect-inputoutput-tofrom-the-debug-target) – starball Feb 27 '23 at 22:26

1 Answers1

1
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 ("''").

starball
  • 20,030
  • 7
  • 43
  • 238