Seite 1 von 1

Subprocess Problem

Verfasst: Mittwoch 11. Oktober 2017, 20:15
von Peter1977
Hallo,

Habe folgenden Code

Code: Alles auswählen

        pdf = canvas.Canvas(r'/opt/bash/protokoll.pdf')
        pdf.setPageSize((89*mm,40*mm))
        pdf.setFont("Courier-Bold", 8)
        pdf.drawString(10*mm,35*mm,"Auftrag:")
        pdf.drawString(10*mm,30*mm,"Material:")
        pdf.drawString(10*mm,25*mm,"Groesse:")
        pdf.drawString(10*mm,20*mm,"Gewicht:")
        pdf.drawString(10*mm,15*mm,"Kundenartikel:")
        
        pdf.setFont("Courier", 4)
        pdf.drawString(10*mm,3*mm,time.strftime("%d.%m.%Y %H:%M:%S"))
        
        pdf.showPage()            
        pdf.save()
        subprocess.call('lpr -P DYMO_LabelWriter_450', 64, '/opt/bash/protokoll.pdf')
dieser Funktioniert bis auf subprocess

dieser führt dann zu einem Traceback

Code: Alles auswählen

Traceback (most recent call last):
  File "auftraege.py", line 79, in DruckTest
    subprocess.check_call('lpr -P DYMO_LabelWriter_450',128, '/opt/bash/protokoll.pdf')
  File "/usr/lib/python3.4/subprocess.py", line 556, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.4/subprocess.py", line 537, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Keine Berechtigung
pi@raspberrypi:~ $
wenn ich in der Konsole das Direkt aufrufe

lpr -P DYMO_LabelWriter_450' /opt/bash/protokoll.pdf

wird es Korrekt Ausgedruckt

wenn ich bei subprocess die 64 Weglasse
dann kommt der Fehler "bufsize must be an integer"

Wie muss ich den subprocess richtig ausführen?

mfg Peter

Re: Subprocess Problem

Verfasst: Mittwoch 11. Oktober 2017, 20:30
von Sirius3
@Peter1977: am besten ruft man Funktionen so auf, wie sie in der Dokumentation beschrieben sind. Der Stacktrace passt übrigens nicht zum Code.

Code: Alles auswählen

subprocess.call(['lpr', '-P', 'DYMO_LabelWriter_450', filename])

Re: Subprocess Problem

Verfasst: Donnerstag 12. Oktober 2017, 15:50
von Peter1977
Hallo,

Danke Funktioniert


mfg Peter