I m试图执行谷歌灯。 在我的一组档案上打字,并将结果收集到一个记录档案中。 然而,我未能在分处理模块上安装。 我目前的法典在这里是:
import os, subprocess
rootdir = "C:/users/me/Documents/dev/"
srcdir = "project/src/"
with open(rootdir+srcdir+"log.txt", mode= w , encoding= utf-8 ) as logfile:
for subdir, dirs, files in os.walk(rootdir+srcdir):
for file in files:
if file.endswith(".h") or file.endswith(".cpp"):
filewithpath=os.path.join(subdir, file)
cmd=[ c:/Python27/python.exe , C:/users/me/Documents/dev/cpplint.py , --filter=-whitespace,-legal,-build/include,-build/header_guard/ , filewithpath]
output = subprocess.check_output(cmd)
logfile.write(output.decode( ascii ))
采用上述法典将产生一个错误:
File "C:Python32libsite.py", line 159
file=sys.stderr)
^ SyntaxError: invalid syntax Traceback (most recent call last): File "C:UsersmeDocumentsdevprojectsrcverifier.py", line 19, in <module>
output = subprocess.check_output(cmd) File "C:Python32libsubprocess.py", line 511, in check_output
raise CalledProcessError(retcode, cmd, output=output) subprocess.CalledProcessError: Command [ c:/Python27/python.exe , C:/users/me/Documents/dev/cpplint.py , --filter=-whitespace,-legal,-build/include,-build/header_guard/ , C:/users/me/Documents/dev/project/src/aboutdialog.cpp ] returned non-zero exit status 1
如果我用一个更简单的东西来替代 cm子:
cmd=[ C:/WinAVR-20100110/bin/avr-gcc.exe , --version ]
然后,文字按预期运作。
I have also tried to use a single command string instead of a list of strings as cmd, but the result is the same. When debugging the code, I copied the list-of-strings-turned-into-the-command-line-command from the debugger and ran it in the Windows command line, and the command ran as expected.
The Python interpreter running my script is Python 3.2. Any tips are greatly appreciated.