Ich habe ein Python-Skript für Windows erstellt, um jede Datei in einem Verzeichnis zu drucken. Um dies zu tun, verwende ich Ghostscript und Gsprint.Datei nicht gefunden Fehler mit Python, kein Fehler in cmd
Wenn ich das Skript zu starten, gibt es einen Fehler WindowsError: [error2] file not found
Wenn ich die gleiche Befehlszeile in cmd starten, gibt es keine Fehler und die pdf gedruckt wird ...
hier ist mein Skript:
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)
der erzeugte Pfad für die Datei ist: C:\Users\GREG\Downloads\DHL-575555338523255087006833669.pdf
Zurückverfolgungs:
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
Ich Fenster 10 mit Python 2.7
Wie starten Sie das Skript? Ist 'gsprint' in PATH? – syntonym
ja gsprint ist im Pfad –
das Skript wird mit Leerlauf gestartet - edit: mit cmd es ist das gleiche –