Issue
I'm sure this is something simple, but I'm trying several settings and I just can't seem to get this to work.
I have the following code:
import subprocess
p = subprocess.Popen('mkdir -p /backups/my_folder', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
This is running in a flask
application on nginx
and python 3
When this executes I'm getting the following error:
/bin/sh: 1: mkdir: not found
I've tried with shell=False
, I've tried with Popen(['mkdir', ...])
, and I've tried subprocess.run
like this question/answer
If I run with shell=False, I get the following error:
Error: [Errno 2] No such file or directory: 'mkdir -p /backups/my_folder': 'mkdir -p /backups/my_folder'
When I do /bin/mkdir
, it works. But, there are other commands which call sub commands that fail (tar
calling gz
for instance)
What am I missing to get this to work?
Running:
Debian 9.8, Nginx 1.14.0, Python 3.6.8
EDIT
I need this to work for other commands as well. I know I can use os.makedirs
, but I have several different commands I will be executing (rsync, ssh, tar, and more)
Solution
I found the problem.
I realized that my /etc/systemd/system/site.service
uWSGI settings had a hard coded path:
Environment = /usr/local/bin
Once, I changed this to include /bin
, all my subprocess commands executed just fine.
Answered By - CodeLikeBeaker Answer Checked By - Dawn Plyler (WPSolving Volunteer)