How can I execute a command who has input

I want to execute a python script that has 3 inputs.

so I want to execute a script in a shell with one line and pass the values ​​of the inputs to it.

I've seen one solution for this, but it only works if I only have one input. the command looks like this:

$ echo "params input" | python myscript.py

      

the problem is the command doesn't work if i have more than 1 input

any suggestion please? thank

+3


source to share


3 answers


use the here-doc command:



python myscript.py <<EOF
input line 1
input line 2
input line 3
EOF

      

+6


source


if the python file is yours:

1) Add this to the first line of your python file:

 #!/usr/bin/python

      

2) in shell make file executable:



chmod +x your_python_file.py

      

3) exec as a compiled program or bash script:

./your_python_file.py param1 param2 param3

      

+1


source


You can use the argparse module that python provides: argparse tutorial

Then you should write the following:

python myscript.py arg1 arg2 arg3

      

0


source







All Articles