2

I'm trying to call a bash function that I've defined in my .profile from a python program. For context, my function calls chef's knife command like so:

  function knife-LHR() {
    knife $@ -c ~/.chef-LHR/knife.rb
  }

If you're wondering why I don't just incorporate the function's logic into my python program, its because my users define this function in their bash profiles and my intent is to support their usage of (in this case) the knife command.

How can I accomplish this using python subprocess?

1 Answer 1

6

I imagine that the best way to do this would be to start up a bash process and have it envoke the command:

import subprocess
subprocess.call(['bash', '-c', '. ~/.profile && knife-LHR'])
Sign up to request clarification or add additional context in comments.

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.