FAQ
I am am trying to run the following command via subprocess

lpr -P printqueue filetoprint

I cannot seem to get it to work and return stderr

I think the issue is how to specify the arguments

I am trying

subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)

but get error :

Traceback (most recent call last):
File "testopen.py", line 6, in ?
subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
File "/usr/python2.4/lib/python2.4/subprocess.py", line 558, in __in
it__
errread, errwrite)
File "/usr/python2.4/lib/python2.4/subprocess.py", line 991, in _exe
cute_child
raise child_exception
OSError: [Errno 2] No such file or directory

Search Discussions

  • Peter Otten at Aug 4, 2010 at 11:08 am

    loial wrote:

    I am am trying to run the following command via subprocess

    lpr -P printqueue filetoprint

    I cannot seem to get it to work and return stderr

    I think the issue is how to specify the arguments

    I am trying

    subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
    This looks for an executable called "lpr -P"; try

    subprocess.Popen(['lpr', '-P' ,'laserlpr','/etc/hosts'], shell=False)
    but get error :

    Traceback (most recent call last):
    File "testopen.py", line 6, in ?
    subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
    File "/usr/python2.4/lib/python2.4/subprocess.py", line 558, in __in
    it__
    errread, errwrite)
    File "/usr/python2.4/lib/python2.4/subprocess.py", line 991, in _exe
    cute_child
    raise child_exception
    OSError: [Errno 2] No such file or directory
  • Loial at Aug 4, 2010 at 11:38 am
    Thanks...that worked.

    I have also been trying to get the return code and standard error.

    How do I access these?

    #!/usr/bin/python
    import os
    import subprocess
    process=subprocess.Popen(['lpr', '-P' ,'raserlpr','/etc/hosts'],
    shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    print process.communicate()







    On 4 Aug, 12:08, Peter Otten wrote:
    loial wrote:
    I am am trying to run the following command via subprocess
    lpr -P printqueue filetoprint
    I cannot seem to get it to work and return stderr
    I think the issue is how to specify the arguments
    I am trying
    subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
    This looks for an executable called "lpr -P"; try

    subprocess.Popen(['lpr', '-P' ,'laserlpr','/etc/hosts'], shell=False)


    but get error :
    Traceback (most recent call last):
    ? File "testopen.py", line 6, in ?
    ? ? subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
    ? File "/usr/python2.4/lib/python2.4/subprocess.py", line 558, in __in
    it__
    ? ? errread, errwrite)
    ? File "/usr/python2.4/lib/python2.4/subprocess.py", line 991, in _exe
    cute_child
    ? ? raise child_exception
    OSError: [Errno 2] No such file or directory- Hide quoted text -
    - Show quoted text -
  • James Mills at Aug 4, 2010 at 11:50 am

    On Wed, Aug 4, 2010 at 9:38 PM, loial wrote:
    I have also been trying to get the return code and standard error.
    p = Popen("..., stderr=PIPE)

    Look up the docs for subprocess.Popen

    cheers
    James

    --
    -- James Mills
    --
    -- "Problems are solved by method"

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 4, '10 at 10:13a
activeAug 4, '10 at 11:50a
posts4
users3
websitepython.org

3 users in discussion

Loial: 2 posts Peter Otten: 1 post James Mills: 1 post

People

Translate

site design / logo © 2022 Grokbase