Reputation: 67
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
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
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
Reputation: 781310
use a here-doc:
python myscript.py <<EOF
input line 1
input line 2
input line 3
EOF
Upvotes: 6