0

How can I call a function from a python script (Ubuntu shell) but also pass a config parameter at the same time? A relevant SO post does not seem to address that.

This is what I have for now:

$ python -c ' from python_library import * ; function() ; -config /path/to/config/file '

The above fails. And so do the following (as many other) combinations:

    $ python -c ' from python_library import * ; function() -config /path/to/config/file '

or

    $ python -c ' from python_library import * ; function() ; -config "/path/to/config/file" '

Thanks!

2
  • ` -config "/path/to/config/file"` is not python code, why are you including it in the quoted command Commented Jul 12, 2018 at 16:04
  • I am trying to pass a parameter (a config file) to my script, and the examples included in the original post are failed attempts to do that. Commented Jul 12, 2018 at 16:06

2 Answers 2

1

You need to pull the conf arg out as another argument to python

$ python -c ' from python_library import * ; function()' -config /path/to/config/file
Sign up to request clarification or add additional context in comments.

2 Comments

it worked (without the lone '-', that was included in your original post), thank you!
If you would like to add & at the end in order your command to run at the background and free up your shell prompt to issue another command?
1

You could use environment variable for that:

MYPARAMETERS="-config /path/to/config/file" python -c "import os,sys;sys.argv = os.environ['MYPARAMETERS'].split(); import python_library import * ; function()"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.