3

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
2
  • 1
    Can you minimize your examples so they don't rely on packages and such. Maybe change the examples to echo some_root_file or summin'. In other words, can you make a minimal, runnable sample? Commented May 25, 2014 at 8:09
  • Okay, added runnable example. Commented May 25, 2014 at 8:12

1 Answer 1

3

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?).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that solved the problem. (removing shell=True). And yeah, meant: /dev/null (was thinking of NUL from Windows Batch).
Confirmed working from bash; but not from the .py file. returned non-zero exit status 127

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.