7

I am using VScode and I would like to debug a program that is used with a pipe command.

In the console, I run my program with

cat dataset.txt | python my_program.py

How can I configure VSCode to pass the cat command so I can debug the program correctly?

I suspect I need to edit launch.json?

{
    "name": "Python: Current File (Integrated Terminal)",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal"
},
Michael
  • 2,436
  • 1
  • 36
  • 57
  • perhaps this can help —> https://stackoverflow.com/q/36688454/6817835 – gold_cy Jan 05 '19 at 15:13
  • How about passing the path to `dataset.txt` to your `my_program.py` and then read the file's content within the program? – HaaLeo Jan 05 '19 at 15:24
  • Thanks for your comments. Indeed I can change the behaviour of the program - this is actually how I debug the program for the moment. I was hoping to have a quicker way to perform the action with any behaviour modification. – Michael Jan 05 '19 at 15:33
  • https://stackoverflow.com/a/60942159/1901067 https://stackoverflow.com/a/69744570/1901067 https://stackoverflow.com/a/73798230/1901067 https://stackoverflow.com/a/63252402/1901067 – David Jan 08 '23 at 08:39
  • https://calvh.medium.com/how-to-pass-input-files-to-stdin-in-vscode-cb31cd7740b8 – David Jan 10 '23 at 08:41

1 Answers1

6

If you change "console" to "externalTerminal", when you run the program an external terminal window will open. This window has stdin connected to the keyboard, so if you type or paste content it will be passed to the program until you send or type ctrl-z. stdout goes to the window. Debugging and breakpoints work as expected.

bashley
  • 76
  • 1
  • 2