简体   繁体   中英

Passing parameters to python script from bash file

I have a python application which starts a websocket on the port which is specified as a parameter to the python application. I have done the passing of argument successfully through the batch(.bat) file in windows. In windows I am passing the parameter as follows: python server.py -p 8000

Now I need to achieve the same in ubuntu 12.04 through the bash file. I am starting the python application as a service from bash file. Code of bash file:

PYPATH="/usr/bin/python"
DEAMON="./server.py"

start-stop-daemon --start --background --name $DEAMONNAME --pidfile $PIDFILE --make-pidfile  --user $USER --group $USER --chuid $USER -d $WORKINGDIR --exec $PYPATH $DEAMON 

This works fine when I run as it is, but it takes default port. I pass parameter as follows :

DEAMON="./server.py -p 8004"

This gives me following error:

start-stop-daemon: invalid option -- 'y'
Try 'start-stop-daemon --help' for more information.
...fail!

Please can any one help me in passing the parameter to the python application from bash file to achieve the same effect as in windows ?

Thanks in advance.

Move any arguments not meant directly for start-stop-daemon to the very end of the command after -- so that they are passed through:

PYPATH="/usr/bin/python"
DEAMON="./server.py -p 8004"

start-stop-daemon --start --background --name $DEAMONNAME --pidfile $PIDFILE --make-pidfile --user $USER --group $USER --chuid $USER -d $WORKINGDIR --exec $PYPATH -- $DEAMON

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM