pythonvisual-studio-codestdin

How to setup Visual Studio Code stdin/stdout redirection for Python (debugger)?


I am using Visual Studio Code to debug my Python code.

I want to redirect one text file in stdin and the output be written in another file.

I can reach that by running python directly using the following syntax:

python code.py < input.txt > output.txt

Is there a way to allow that while debugging the script? If that is not possible, can I create a configuration for running python with that parameters. I tried using args parameter in the launch.json, but those are all placed into quotes that defeats the purpose of this redirection.


Solution

  • There isn't any built-in solution, but if you modified your app to replace sys.stdin and sys.stdout with what you would like to be considered stdin and stdout you could get the same effect.