Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run npm commands using Python subprocess

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.

like image 577
Evan Siroky Avatar asked Mar 06 '15 01:03

Evan Siroky


1 Answers

I needed to specify shell=True in the check_call.

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

subprocess.check_call('yuidoc --help', shell=True)
like image 63
Evan Siroky Avatar answered Sep 21 '22 21:09

Evan Siroky