How to redirect standard input/output inside PyCharm?

Sorry for a primitive question:

how to redirect stdin/stdout to some files when debugging a python program inside the PyCharm IDE?

I've tried to edit configuration by setting the "Script parameters" to something like "< input.txt > output.txt",

but this does not work: the IDE displays the top line like "C:\Python27\python.exe C:/file1.py < input.txt > output.txt"

and still waits for input text.

Thanks in advance!

2 comments

Hello Andrey,

The standard input/output redirection is a feature of cmd.exe and not of

the standard OS processes, and it's not directly supported by PyCharm. You

can either set up an external tool via Settings | External Tools that would

run cmd /c python.exe your_script.py, or teach your own script to accept

an input from a file in addition to standard input.

Sorry for a primitive question:

how to redirect stdin/stdout to some files when debugging a python

program inside the PyCharm IDE?

I've tried to edit configuration by setting the "Script parameters" to

something like "< input.txt > output.txt",

but this does not work: the IDE displays the top line like

"C:\Python27\python.exe C:/file1.py < input.txt > output.txt"

and still waits for input text.

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0

Dmitry, thank you for fast response!

The both suggested approaches work fine, though in the first one (through an external tool) it seems that it's impossible to use PyCharm debugger. So I just used your second suggestion and specified input/output files in the python script explicitly.

0

Please sign in to leave a comment.