我为Windows制作了一个python脚本,以在目录中打印每个文件。为此,我使用了ghostscript和gsprint。
当我启动脚本时,出现错误 WindowsError: [error2] file not found
如果我在cmd中启动相同的命令行,则不会出现错误,并且会打印pdf ...
这是我的脚本:
for f_name in files_in_dir:
fullpath_file = os.path.join(base_print, path_print_source, f_name)
carrier = f_name.split('-')[0]
new_path = os.path.join(base_print, carrier + '_printed')
new_fullpath_file = os.path.join(new_path, f_name)
print Tools.format_txt("traitement du fichier %s" % f_name)
print Tools.format_txt("traitement du fichier %s" % f_name, carrier)
p = subprocess.Popen(['gsprint', '-printer', printer,'-dPDFFitPage', fullpath_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if out:
print Tools.format_txt(out)
if err:
print Tools.format_txt(err, level="error")
print Tools.format_txt("fichier %s envoyé pour impression" % f_name, carrier)
if not os.path.exists(new_path):
os.makedirs(new_path)
os.rename(fullpath_file, new_fullpath_file)
该文件的生成路径为: C:\Users\GREG\Downloads\DHL-575555338523255087006833669.pdf
追溯 :
Traceback (most recent call last):
File "python-print.py", line 95, in <module>
sys.exit(main()) # si le script est utilis├® comme un module, on n'ex├®cute pas le script
File "python-print.py", line 61, in main
p = subprocess.Popen(['gsprint', '-printer', printer,'-dPDFFitPage', fullpath_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] Le fichier spÚcifiÚ est introuvable
我正在将Windows 10与python 2.7一起使用
经过多次尝试,我设法解决了这个问题:
c:\program files
我安装了Gsprint,然后将其移动并安装在c:\GSP
没有空格的路径中,并且效果很好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句