我为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
我正在使用带有python 2.7的Windows 10
答案 0 :(得分:0)
经过多次尝试,我设法解决了这个问题:
Gsprint安装在c:\program files
我移动它并安装在c:\GSP
所以没有空格的路径,它运行正常。