I am working on web game which uses python and javascript. I wanted to write a python script that automatically builds my js files using browserify. In order to run browserify, I need to use the local installation of it in node_modules/.bin
. I read that the command npm bin
will give me the location of npm binaries so I wanted to use it in my script.
I tried to do
import subprocess
c = subprocess.run(("npm", "bin"), capture_output=True)
but that gave me an error:
FileNotFoundError: [WinError 2] The system cannot find the file specified
After searching a bit, I found that using shell=True
fixes this:
import subprocess
c = subprocess.run(("npm", "bin"), capture_output=True, shell=True)
However, after reading this question I realized that using shell=True
isn't a good practice and it can lead to security issues.
So my question is, how can I run an external command using python without the risk of shell=True
?
I am probably going to face the same problem when I try to run browserify through python (haven't tried it yet), so I should ask this question now.
Thanks in advance.