Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Running lpr on windows from python Date: Thu, 21 Apr 2016 00:07:26 +1000 Lines: 31 Message-ID: References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de /LUE79sqH3TeLn6HuggBCgwZiiVJzjkvUHZViGskYGFg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'binary': 0.05; 'cc:addr :python-list': 0.09; 'rules.': 0.09; 'python': 0.10; 'subject:python': 0.14; 'wed,': 0.15; 'argument': 0.15; '2016': 0.16; 'command,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'slashes': 0.16; 'subject:windows': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; 'typing': 0.18; 'shell': 0.18; 'windows': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'explicit': 0.22; 'file.': 0.22; 'pass': 0.22; 'trying': 0.22; 'split': 0.23; 'recognized': 0.24; 'header:In-Reply-To:1': 0.24; 'command': 0.26; 'external': 0.27; 'error': 0.27; 'raw': 0.27; 'separate': 0.27; 'message-id:@mail.gmail.com': 0.27; 'arguments,': 0.29; 'follows': 0.29; 'there.': 0.30; "i'm": 0.30; 'run': 0.33; "skip:' 20": 0.34; 'running': 0.34; 'received:google.com': 0.35; "isn't": 0.35; 'but': 0.36; 'list,': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'wrong': 0.38; 'means': 0.39; 'sure': 0.39; 'subject:from': 0.39; 'where': 0.40; 'some': 0.40; '20,': 0.66; 'forward': 0.66; 'cut': 0.67; 'protect': 0.76; 'prompt': 0.79; 'anywhere.': 0.84; 'chrisa': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=aQYduK0MVhH93SW007/UgsIMfLNqFHF4TCg3uebqPPQ=; b=ZVQGQp59w1sOIZHbx4/hxma1C+FD7d1ezwlfctbVlZGLM/K+5iIaBxq1g1pal+zgcX xhKgft3KB7bNQS4aTAjFcGZVYmlVjA/ilonzmTJWcrvQAHt0OTaVnQE49Vw9ET7VocsP q97TxdMhzGIM55UTFm3R+eII1uC41aHiyYH2djeqGjPragcqx78IwdYCE4uWIoUG0dsw eYBiqdmZGTOVNot+sSWsJPck87Yn/hXAI7ufUlu2kSDLG0r7QF0U5a9vuJRWbbYPrnHi F7JRaMx/g/Et+wp2QF2w/oJ6W+POlARCHfQAW7/fJOPHHPhTQtmRE6wexOvyTCv5lHPO 6Srg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=aQYduK0MVhH93SW007/UgsIMfLNqFHF4TCg3uebqPPQ=; b=KGpMKs8mBW/88948g35Z2GXkMfbsDJE7hZ/AACPQML8CMlnqqOdfjTuG/QfTZQ9fO1 vZ+cjflFsPEHokACiGhnkrRuuKb47FprcieYi1vZ+m++lO60C/8TTSq8qdQO/JrMjDBU OTphRxsU847Gn6374mMCfm52pF+LXD0OSiYcgwTvFdCVB8T87dPxIntqn49lL+WYJDm7 qSkuOiqlbbjsB9KmrVnuFP1n98bhL4LlWGEMHcD4f72ckgRi0ovzNmH9wkmNirktDuOc eI0wdHBERW2WGqwlazT63GKpqMzcSP/fEIiIMcQqfjMtiefbarohpG8K0afnpssEoiLC uTdw== X-Gm-Message-State: AOPr4FWMyQK3s/G+TZ2sO7t332DWHNQmmUZ65majsYTQWS46jXLxAzvN3cPnfr5X0Godbg3ThRwrEHHfpFuxqA== X-Received: by 10.50.111.15 with SMTP id ie15mr1560474igb.94.1461161246496; Wed, 20 Apr 2016 07:07:26 -0700 (PDT) In-Reply-To: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Xref: csiph.com comp.lang.python:107411 On Wed, Apr 20, 2016 at 11:57 PM, loial wrote: > I am trying to run lpr from python 2.7.10 on windows > > However I always get the error > 'C:/windows/system32/lpr.exe ' is not recognized as an internal or external command, > operable program or batch file. > > Even though typing the same at the command prompt works OK > > > Any ideas? > > I am using subprocess as follows > > process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > where command line is > C:/windows/system32/lpr.exe -S 172.28.84.38 -P RAW C:/john/myfile You''re running that through the shell, which means you have to abide by shell rules. I don't have a Windows handy, but I'm pretty sure its shell isn't happy with forward slashes in the command line; I might be wrong there. My recommendation: Split that into separate arguments, pass them as a list, and remove shell=True. And unless you need to be completely explicit for some reason (eg to protect against path-based exploits), cut the first argument to just "lpr" and let the binary be found anywhere. ChrisA