I’m running Python 3.6 on an Centos box.
Here’s my non-working code
shell_command = subprocess.check_output(["ll"],shell=True, universal_newlines=True, executable='/bin/bash')
Here’s the output:
/bin/bash: ll: command not found
Traceback (most recent call last):
File "./snmp_test.py", line 17, in <module>
shell_command = subprocess.check_output(["ll"],shell=True, universal_newlines=True, executable='/bin/bash')
File "/data/prod_envs/pythons/python36/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/data/prod_envs/pythons/python36/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ll']' returned non-zero exit status 127
So judging by the error
/bin/bash: ll: command not found
bash doesnt know ll
which is weird, because echo "$SHELL"
returns
/bin/bash
and via CLI, the ll
command works.
I can’t figure out what the issue is. Does anybody have an idea?
2
Answers
found out that 'll' was an alias , and changed the line of code to
and now it works like a charm.
Don’t rely on aliases from your personal shell configuration being defined; spell out the command you expect it to resolve to.