我有一个运行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
:
如何使lessc
在不使用shell=True
的情况下运行?在
从https://docs.python.org/3/library/subprocess.html#subprocess.Popen和https://docs.python.org/2/library/subprocess.html#subprocess.Popen:
已经是cited by @JBernardo。在
所以,让我们试试:
where lessc
实际上说明这意味着,要执行的文件是
^{pr2}$lessc.cmd
,而不是某个.bat
文件。事实上:因此,如果指定完整路径,则该确实有效。我想你在写this experience的时候有个打字错误。你可能是写了
.bat
而不是.cmd
?在如果不想将
lessc
的完整路径修补到脚本中,可以为自己烘焙一个where
:然后你可以写下:
将文件更改为小蝙蝠,或创建调用lessc的.bat文件。这样,Windows会将文件识别为批处理文件,并将正确执行。在
根据.bat文件的位置,您可能还需要设置cwd。在
相关问题 更多 >
编程相关推荐