I have a Python script (Python 3.6) that is intended to be called from a shell script. This shell script defines some functions prior to calling the Python script. In the Python code, I'd like to use these functions within a subprocess.
Here's an example of what I'm trying to do
# Shell script
function func1() {
echo "func1 completed"
}
python /path/to/my_script.py
The Python script
# my_script.py
import subprocess
p = subprocess.Popen("func1",
stdout = subprocess.PIPE,
shell = True)
However, when running that, I get the error: /bin/sh: func1: command not found
.
I've tried it using shell = False
, passing env = os.environ
, and with os.system
but I get similar errors. Is there a way this can be done?