Using stdin in pycharm

I started using pycharm and I can't seem to

on the command line I use to run the program as follows:

python parse_file.py < test.txt 

when parse_file.py can be simple:

 import sys for line in sys.stdin: print line 

I can not find in the configuration where to do this. I tried typing something like <test.txt in script parameters, but no luck

I looked at https://www.jetbrains.com/pycharm/help/run-debug-configuration-python.html

but no luck there

thanks

+7
python stdin pycharm
source share
2 answers

PyCharm startup configurations do not support standard input redirection. Please consider modifying your script so that it reads its input directly from the file, and not through standard input redirection.

+4
source share

There is a solution, but it is not portable, and you will have to adapt it to your OS. I am describing this for Windows.

  • In the menu "File"> "Settings"> "Tools"> "External Tools" create a new configuration, specify the name of your choice (for example: input redirection cmd).
  • At the bottom of the form for the type of program cmd.exe . In the parameters, enter /c "$JDKPath$ parse_file.py < test.txt" ( Double quotes are important ) and configure the working directory in the folder where your files are stored.
  • If you wish, you can play with macros (buttons on the right) to replace some hard-coded values ​​with the equivalent of a variable, which can help you turn your external tool configuration into something reusable.

Now you can right-click on the file in your project and select "External Tool> cmd input redirected".

The only unpleasant thing in this process is that you cannot restart the external tool using the shortcut when editing the code. To restart, you need to set the focus on the Run tab, and then use Ctrl + F5 (or just click the green Rerun triangle 'cmd input redirected'

I hope for this help, I welcome

+1
source share

All Articles