A T
A T

Reputation: 13826

Running code from python has different permission than from bash?

First step

$ sudo adduser foo_user
$ mkdir /tmp/foo-user && chown foo_user:foo_user $_
$ sudo npm install -g less  # Install Node.js and NPM for this
$ echo ".box {color: red}" | sudo -u foo_user tee /tmp/foo-user/main.less

Python

$ sudo -u foo_user python -c "from subprocess import check_output, STDOUT;
                              print check_output(['/usr/local/bin/lessc',
                                                  '/var/lib/nginx/body/main.less'],
                                                  stderr=STDOUT, shell=True);"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/usr/local/bin/lessc', '/tmp/foo-user/main.less']' returned non-zero exit status 1

Bash

$ sudo -u foo_user /usr/local/bin/lessc /tmp/foo-user/main.less >NULL && echo $?
0

Upvotes: 3

Views: 610

Answers (1)

Chris Warrick
Chris Warrick

Reputation: 1629

With shell=True, you must use a string, not a list of arguments. This is likely causing your problems (which may not be permission problems — in fact, you only know that lessc exits with 1 and not the reason for it).

Also, in Python, you run the command. In Bash, you run the command and redirect stdout to a file named NULL (did you mean /dev/null?).

Upvotes: 3

Related Questions