我有一个运行lessc
的函数(使用npm install -g less
):
>>> import subprocess >>> subprocess.Popen(['lessc']) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\subprocess.py", line 679, in __init__ errread, errwrite) File "C:\Python27\lib\subprocess.py", line 896, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified
不幸的是,除非我添加shell=True
,否则不起作用:
>>> subprocess.Popen(['lessc'], shell=True) <subprocess.Popen object at 0x01F619D0>
我能做些什么来让lessc
运行而不使用shell=True
?
将文件更改为lessc.bat,或创建调用lessc的.bat文件。 这样,该文件将作为批处理文件被Windows识别,并将被正确执行。
除此之外,您可能还需要设置cwd,具体取决于.bat文件的位置。