I have this python script: postpycess.py to draw data from a mesh file airfoil.p3d. This script was designed to work with input not using arguments, so I created an input file commands.txt and redirect it to the script.

commands.txt: (note that the first input which is the name of the airfoil should be provided without extension .p3d)


In Windows I could run this as follows:

python postpycess.py < commands.txt

But Unfortunately, When I run that command on Ubuntu 20.04, the script fails:

The current working dir: /tmp/allworks/python/mwe

This is Postpycess, the CFD postprocessor
Version: 1.1
.p3dr project name: Error: can't read the file airfoil

However, the following works just file:

printf 'airfoil\n1\n1\nq\nq\n' | python postpycess.py

I've tried hard to narrow down the cause in the python script and create a minimal example that could reproduce the same issue without success.

Could you please, explain why redirecting the input from the file fails in Linux?

I appreciate your help.

1 Answer 1


Your commands.txt has probably its lines terminated by \r\n (windows-style) instead of just \n (unix-style).

Just convert it to unix with sed -i 's/\r//' commands.txt or run your script as sed 's/\r//' commands.txt | python postpycess.py.

  • Oh, brilliant, that's solves the issue. Sep 13, 2020 at 10:46
  • Also dos2unix removes carriage returns
    – Quasímodo
    Sep 13, 2020 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .