Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107410 > unrolled thread
| Started by | loial <jldunn2000@gmail.com> |
|---|---|
| First post | 2016-04-20 06:57 -0700 |
| Last post | 2016-04-22 12:04 -0500 |
| Articles | 12 — 6 participants |
Back to article view | Back to comp.lang.python
Running lpr on windows from python loial <jldunn2000@gmail.com> - 2016-04-20 06:57 -0700
Re: Running lpr on windows from python Chris Angelico <rosuav@gmail.com> - 2016-04-21 00:07 +1000
Re: Running lpr on windows from python loial <jldunn2000@gmail.com> - 2016-04-20 07:25 -0700
Re: Running lpr on windows from python Tim Golden <mail@timgolden.me.uk> - 2016-04-20 15:08 +0100
Re: Running lpr on windows from python Random832 <random832@fastmail.com> - 2016-04-20 10:09 -0400
Re: Running lpr on windows from python loial <jldunn2000@gmail.com> - 2016-04-20 07:21 -0700
Re: Running lpr on windows from python Tim Golden <mail@timgolden.me.uk> - 2016-04-20 15:58 +0100
Re: Running lpr on windows from python eryk sun <eryksun@gmail.com> - 2016-04-20 22:10 -0500
Re: Running lpr on windows from python Stephen Hansen <me+python@ixokai.io> - 2016-04-20 14:01 -0700
Re: Running lpr on windows from python loial <jldunn2000@gmail.com> - 2016-04-22 04:30 -0700
Re: Running lpr on windows from python loial <jldunn2000@gmail.com> - 2016-04-22 08:07 -0700
Re: Running lpr on windows from python eryk sun <eryksun@gmail.com> - 2016-04-22 12:04 -0500
| From | loial <jldunn2000@gmail.com> |
|---|---|
| Date | 2016-04-20 06:57 -0700 |
| Subject | Running lpr on windows from python |
| Message-ID | <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-04-21 00:07 +1000 |
| Message-ID | <mailman.26.1461161254.12923.python-list@python.org> |
| In reply to | #107410 |
On Wed, Apr 20, 2016 at 11:57 PM, loial <jldunn2000@gmail.com> 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
[toc] | [prev] | [next] | [standalone]
| From | loial <jldunn2000@gmail.com> |
|---|---|
| Date | 2016-04-20 07:25 -0700 |
| Message-ID | <6171cb8a-988a-49ea-a767-d73824685fea@googlegroups.com> |
| In reply to | #107411 |
I get the same issue if I just specify "lpr" rather than a full path, i.e. it works from the command prompt(with forward slashes), but not from python
[toc] | [prev] | [next] | [standalone]
| From | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| Date | 2016-04-20 15:08 +0100 |
| Message-ID | <mailman.27.1461161336.12923.python-list@python.org> |
| In reply to | #107410 |
On 20/04/2016 14:57, 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 > Ummm.. Do you actually have a program called lpr.exe in that location? It's not usual on Windows. (I rather assume you do since you give the full path, but still...) IOW, what happens if you type: dir C:\windows\system32\lpr.exe at a command promopt? Also: are you on a 64-bit system? If so, c:\windows\system32 probably isn't where you think it is. cf, for example: https://mail.python.org/pipermail/python-win32/2012-March/012121.html TJG
[toc] | [prev] | [next] | [standalone]
| From | Random832 <random832@fastmail.com> |
|---|---|
| Date | 2016-04-20 10:09 -0400 |
| Message-ID | <mailman.28.1461161353.12923.python-list@python.org> |
| In reply to | #107410 |
On Wed, Apr 20, 2016, at 09:57, 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 It does? This command doesn't exist on my machine. It's not a standard part of windows. Just to check though, are you 64-bit windows, and 32 or 64 bit python? (To find out what kind of windows, go to the system control panel - to find out if python is 64-bit look at the value of sys.maxsize, it's 2147483647 on 32-bit systems and 9223372036854775807 on 64-bit) > 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 If all you want to do is print a text file, see http://www.robvanderwoude.com/printfiles.php - these commands may not let you do whatever you're trying to do with that IP address though.
[toc] | [prev] | [next] | [standalone]
| From | loial <jldunn2000@gmail.com> |
|---|---|
| Date | 2016-04-20 07:21 -0700 |
| Message-ID | <7a7e2d01-fcf3-4f14-9531-f19a96700cf3@googlegroups.com> |
| In reply to | #107410 |
As I said, the lpr command works fine from the command prompt but not from python. Everything is 64-bit (windows server 2012).
[toc] | [prev] | [next] | [standalone]
| From | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| Date | 2016-04-20 15:58 +0100 |
| Message-ID | <mailman.30.1461164321.12923.python-list@python.org> |
| In reply to | #107414 |
On 20/04/2016 15:21, loial wrote: > As I said, the lpr command works fine from the command prompt but not from python. Sorry; I did miss that. > Everything is 64-bit (windows server 2012). > Is the Python installation also 64-bit? c:\python27\python.exe -c "import platform; print platform.architecture()" If it is, then I'm not sure what's going on. If it's not, then try copying the lpr.exe to c:\windows\syswow64 and try again. (Or to some other place to which you have access). TJG
[toc] | [prev] | [next] | [standalone]
| From | eryk sun <eryksun@gmail.com> |
|---|---|
| Date | 2016-04-20 22:10 -0500 |
| Message-ID | <mailman.44.1461208295.12923.python-list@python.org> |
| In reply to | #107414 |
On Wed, Apr 20, 2016 at 9:58 AM, Tim Golden <mail@timgolden.me.uk> wrote:
> If it's not, then try copying the lpr.exe to c:\windows\syswow64 and try
> again. (Or to some other place to which you have access).
WOW64 in Windows 7+ has a virtual "SysNative" directory that accesses
the native 64-bit system directory:
if '32bit' in platform.architecture():
lpr = os.path.join(os.environ['SystemRoot'], 'SysNative', 'lpr.exe')
else:
lpr = os.path.join(os.environ['SystemRoot'], 'System32', 'lpr.exe')
[toc] | [prev] | [next] | [standalone]
| From | Stephen Hansen <me+python@ixokai.io> |
|---|---|
| Date | 2016-04-20 14:01 -0700 |
| Message-ID | <mailman.40.1461186123.12923.python-list@python.org> |
| In reply to | #107410 |
On Wed, Apr 20, 2016, at 06:57 AM, loial wrote: > 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 Try making command line: commandline = r"C:\windows\system32\lpr.exe -S 172.28.84.38 -P RAW C:\john\myfile" The r in front of the string makes it a raw string so you don't have to double up the slashes. --- Stephen Hansen m e @ i x o k a i . i o
[toc] | [prev] | [next] | [standalone]
| From | loial <jldunn2000@gmail.com> |
|---|---|
| Date | 2016-04-22 04:30 -0700 |
| Message-ID | <982a6a8e-f987-4e9b-ae2e-90f3d9aad4c9@googlegroups.com> |
| In reply to | #107410 |
Nothing seems to work.
Even doing
import os
os.system("lpr")
still returns
'lpr' is not recognized as an internal or external command,operable program or batch file.
Even though I can run lpr fine from the command prompt
[toc] | [prev] | [next] | [standalone]
| From | loial <jldunn2000@gmail.com> |
|---|---|
| Date | 2016-04-22 08:07 -0700 |
| Message-ID | <fb733951-4abd-44b7-b13c-a24d92009077@googlegroups.com> |
| In reply to | #107488 |
I finally found the solution here : http://www.tomshardware.co.uk/forum/240019-44-error-windows Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the sysWOW64 folder Thanks for all your efforts
[toc] | [prev] | [next] | [standalone]
| From | eryk sun <eryksun@gmail.com> |
|---|---|
| Date | 2016-04-22 12:04 -0500 |
| Message-ID | <mailman.19.1461344712.2861.python-list@python.org> |
| In reply to | #107496 |
On Fri, Apr 22, 2016 at 10:07 AM, loial <jldunn2000@gmail.com> wrote:
> I finally found the solution here :
>
> http://www.tomshardware.co.uk/forum/240019-44-error-windows
>
> Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the sysWOW64 folder
Using the virtual "SysNative" directory should work on Windows 7+
(Server 2008 R2). All you need is for CreateProcess to find the
executable. Finding the DLLs is done during process initialization, so
there's no need to copy them from the native System32 directory.
It works for me in 32-bit Python running in Windows 10:
>>> if '32bit' in platform.architecture():
... lpr = os.path.join(os.environ['SystemRoot'], 'SysNative', 'lpr.exe')
... else:
... lpr = os.path.join(os.environ['SystemRoot'], 'System32', 'lpr.exe')
...
>>> print(lpr)
C:\Windows\SysNative\lpr.exe
>>> subprocess.call(lpr)
Sends a print job to a network printer
Usage: lpr -S server -P printer [-C class] [-J job] [-o option]
[-x] [-d] filename
Options:
-S server Name or ipaddress of the host providing lpd service
-P printer Name of the print queue
-C class Job classification for use on the burst page
-J job Job name to print on the burst page
-o option Indicates type of the file (by default assumes
a text file)
Use "-o l" for binary (e.g. postscript) files
-x Compatibility with SunOS 4.1.x and prior
-d Send data file first1
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web