Simo
Simo

Reputation: 67

how can i execute command who have input

i want to execute a python script who have 3 inputs .

so i want to execute the script in the shell by one line command and pass him the inputs values .

i have seen one solution to do that but it works just if i have only one input . the command is like :

$ echo "params input" | python myscript.py

the issue is the command don't work if i have more than 1 input

any suggestion please ? thank you

Upvotes: 3

Views: 65

Answers (3)

cherylcourt
cherylcourt

Reputation: 195

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

Then you would write the following:

python myscript.py arg1 arg2 arg3

Upvotes: 0

obayhan
obayhan

Reputation: 1732

if python file is your own:

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 like a compiled program or bash script:

./your_python_file.py param1 param2 param3

Upvotes: 1

Barmar
Barmar

Reputation: 781310

use a here-doc:

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

Upvotes: 6

Related Questions