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.

Community
  • 1
  • 1
Evan Siroky
  • 9,040
  • 6
  • 54
  • 73

1 Answers1

25

I needed to specify shell=True in the check_call.

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

subprocess.check_call('yuidoc --help', shell=True)
Evan Siroky
  • 9,040
  • 6
  • 54
  • 73
  • 1
    [Invoking by shell is not recommended](https://stackoverflow.com/a/3172488/3936044). I suggest `check_call('npm.cmd --help')`, it's from [this answer](https://stackoverflow.com/a/50045443/3936044) in the related thread you mentioned – Mandera Feb 21 '23 at 12:51