Let say we have a script that accepts arguments, which then dispatches it to subprocess run. When there are no ENV
defined, I can simply dispatch all args directly and call commands, like:
import subprocess
import sys
subprocess.run(sys.argv[1:], check=True)
But if I let say call like this my-script.py A=22; B=33; echo "test"
, then first argument is found as environment variable, not executable.
Is there some good way to recognize when we have ENV
before command to handle it?
P.S. I could use Popen
with shell=True
to propagate it to shell, but I want to preprocess command before executing it (like do extra stuff if I got specific ENV
passed etc).