I have a Python (3.9) script that exists in the following file structure:
L usr
L src
L project_root
L folder_a
L folder_b
L foo.py
L bar.sh
foo.py
contains this line of code, which calls a subprocess bar.sh
and passes some data to it:
subprocess.call(['/usr/src/folder_a/folder_b/bar.sh', f'{some_data}'])
This subprocess call finds the shell script just fine when run locally.
However, when I run this same code in a docker container, I get the following exception:
Exception: [Errno 2] No such file or directory: '/usr/src/folder_a/folder_b/bar.sh'
Troubleshooting steps I have tried:
- I confirmed that the path is correct, both spelling and location
- The docker container's top-level is the
project_root
folder
- I have tried both the relative and exact paths, neither work
- I have SSH'd into the container and checked the files, the shell script is present in the exact directory that I provided.
- I have tried using
os.path.abspath()
to generate the absolute path to the shell script, but it was still not found.
- I have checked
os.cwd
to confirm that the current working directory is usr/src
- I have used
Path(__file__).parent('./bar.sh')
to find the absolute path to the shell script, which just gave me the string /usr/src/folder_a/folder_b/bar.sh
, the same as I've been using.
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…