0

I have a bash script which setups the environment for the application. At the last line of the bash script I call Python:

app_start.sh

exec $PROGRAM_NAME "$@"

where $PROGRAM_NAME is the path to Python, e.g. /usr/bin/python, so this is how I run Python:

./app_start.sh /usr/bin/python

Now, I need this path as program name, i.e. in sys.argv[0] but when I try to get sys.argv, it is empty. Only when I pass a Python script as argument, I can get that script name in sys.argv:

./app_start.sh /usr/bin/python /path/to/script.py

and sys.argv = ['/path/to/script.py'].

My question is, how can I retrieve ALL arguments, i.e. starting with Python path, from sys.argv? I need sys.argv[0] to be /usr/bin/python.

Thanks in advance.

user3132457
  • 789
  • 2
  • 11
  • 29
  • 2
    If you need the python that is being run, you can use [`sys.executable`](https://docs.python.org/2/library/sys.html#sys.executable). – Holloway Nov 20 '19 at 21:09
  • Looks like it was previously answered here https://stackoverflow.com/questions/749711/how-to-get-the-python-exe-location-programmatically – mathew gunther Nov 20 '19 at 21:50

0 Answers0