17

I'm trying to automate the generation of documentation using YUIDOC, but I have a server side framework that heavily uses python, so I'm trying to automate everything from within a python script. I'm able to get the node command to run fine, but whenever I try something I installed using npm, python isn't happy. My project uses Buildout instead of virtualenv, but ideally I'd like to be able to just run these commands from a standalone python file.

Perhaps some code would help explain my situation:

import subprocess
subprocess.check_call('node --help')

#SUCCESS

import subprocess
subprocess.check_call('npm --help')

#FAIL
#WindowsError: [Error 2] The system cannot find the file specified

import subprocess
subprocess.check_call('yuidoc --help')

#FAIL
#WindowsError: [Error 2] The system cannot find the file specified

I already tried adding the folder where the yuidoc and npm stuff lives to the sys.path of python, but that didn't work.

ps, this is sort of a similar question to this question.

1 Answer 1

26

I needed to specify shell=True in the check_call.

subprocess.check_call('npm --help', shell=True)

subprocess.check_call('yuidoc --help', shell=True)
Sign up to request clarification or add additional context in comments.

1 Comment

Invoking by shell is not recommended. I suggest check_call('npm.cmd --help'), it's from this answer in the related thread you mentioned

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.