lpr via subprocess in 2.4

Discussion in 'Python' started by loial, Aug 4, 2010.

  1. loial

    loial Guest

    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
     
    loial, Aug 4, 2010
    #1
    1. Advertising

  2. loial

    Peter Otten Guest

    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
     
    Peter Otten, Aug 4, 2010
    #2
    1. Advertising

  3. loial

    loial Guest

    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 -
     
    loial, Aug 4, 2010
    #3
  4. loial

    James Mills Guest

    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"
     
    James Mills, Aug 4, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Any LPR solution??

    , Sep 6, 2005, in forum: Java
    Replies:
    16
    Views:
    708
  2. Replies:
    13
    Views:
    809
    Donn Cave
    Mar 6, 2007
  3. Peter Beattie

    Controlling gnuplot via subprocess.Popen

    Peter Beattie, Apr 25, 2007, in forum: Python
    Replies:
    3
    Views:
    784
    Grant Edwards
    Apr 25, 2007
  4. hiral
    Replies:
    2
    Views:
    627
    Jean-Michel Pichavant
    May 5, 2010
  5. Huub
    Replies:
    6
    Views:
    124
Loading...

Share This Page