Subprocess Problem

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Peter1977
User
Beiträge: 86
Registriert: Mittwoch 4. September 2013, 14:59

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
Sirius3
User
Beiträge: 17738
Registriert: Sonntag 21. Oktober 2012, 17:20

@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])
Peter1977
User
Beiträge: 86
Registriert: Mittwoch 4. September 2013, 14:59

Hallo,

Danke Funktioniert


mfg Peter
Antworten