Home > Enterprise >  How to give input to python program through bash?
How to give input to python program through bash?

Time:06-24

I want to provide first argument of bash script as filename to python.

I tried this solution from another question:

python main.py <<EOF
$1
EOF

But python raises EOFError: EOF when reading a line , if you add another input in python program.

How to solve it?

CodePudding user response:

You can use sys lib:

import sys

for arg in sys.argv[1:]:
    print (arg)

$ python test.py a b c
a
b
c

in your case it would be something like:

python test.py your/file/path input1 input2
  •  Tags:  
  • bash
  • Related