skip to Main Content

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


  1. Chosen as BEST ANSWER

    found out that 'll' was an alias , and changed the line of code to

    shell_command = subprocess.check_output("ls -l --color=auto",shell=True, universal_newlines=True, executable='/bin/bash')
    

    and now it works like a charm.


  2. Don’t rely on aliases from your personal shell configuration being defined; spell out the command you expect it to resolve to.

    shell_command = subprocess.check_output(["ls", "-l", "--color=auto"], universal_newlines=True)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search